Submission #8813834
Source Code Expand
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx_ori[4] = { -1,0, 1,0 }, dy_ori[4] = { 0,1,0,-1 };
int dx[4] = {0, 0, 0, 0}, dy[4] = {0, 0, 0, 0};
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'
ll mod_pow(ll x, ll p, ll M = MOD) {
ll a = 1;
while (p) {
if (p % 2)
a = a*x%M;
x = x*x%M;
p /= 2;
}
return a;
}
signed main() {
int n, k;
cin >> n >> k;
map<int, ll> dp;
for (ll x = 1; x * x <= n; x++) {
if (n % x == 0) {
dp[x] = 0;
dp[n / x] = 0;
}
}
for (auto itr = dp.begin(); itr != dp.end(); itr++) {
int i = itr->first;
int zi = (i + 1) / 2;
dp[i] = mod_pow(k, zi);
//DEBUG(dp[i]);
for (auto itr2 = dp.begin(); itr2->first < i; itr2++) {
int j = itr2->first;
if (i % j != 0) continue;
(dp[i] -= itr2->second) %= MOD;
}
//DEBUG(pll(i, dp[i]));
}
ll ans = 0;
for (auto itr = dp.begin(); itr != dp.end(); itr++) {
int i = itr->first;
if (i % 2 == 1) {
ans = (ans + itr->second * i % MOD) % MOD;
}
else {
ans = (ans + itr->second * (i / 2) % MOD) % MOD;
}
}
ans = (ans + MOD) % MOD;
cout << ans << endl;
}
Submission Info
Submission Time |
|
Task |
F - Rotated Palindromes |
User |
fuppy0716 |
Language |
C++14 (GCC 5.4.1) |
Score |
1000 |
Code Size |
3178 Byte |
Status |
AC |
Exec Time |
21 ms |
Memory |
384 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
1000 / 1000 |
Status |
|
|
Set Name |
Test Cases |
Sample |
0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt |
All |
0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt |
Case Name |
Status |
Exec Time |
Memory |
0_00.txt |
AC |
1 ms |
256 KB |
0_01.txt |
AC |
1 ms |
256 KB |
0_02.txt |
AC |
1 ms |
256 KB |
0_03.txt |
AC |
2 ms |
256 KB |
1_00.txt |
AC |
1 ms |
256 KB |
1_01.txt |
AC |
1 ms |
256 KB |
1_02.txt |
AC |
2 ms |
256 KB |
1_03.txt |
AC |
2 ms |
256 KB |
1_04.txt |
AC |
1 ms |
256 KB |
1_05.txt |
AC |
1 ms |
256 KB |
1_06.txt |
AC |
1 ms |
256 KB |
1_07.txt |
AC |
1 ms |
256 KB |
1_08.txt |
AC |
2 ms |
256 KB |
1_09.txt |
AC |
2 ms |
256 KB |
1_10.txt |
AC |
2 ms |
256 KB |
1_11.txt |
AC |
2 ms |
256 KB |
1_12.txt |
AC |
2 ms |
256 KB |
1_13.txt |
AC |
2 ms |
256 KB |
1_14.txt |
AC |
2 ms |
256 KB |
1_15.txt |
AC |
2 ms |
256 KB |
1_16.txt |
AC |
21 ms |
384 KB |
1_17.txt |
AC |
21 ms |
384 KB |
1_18.txt |
AC |
21 ms |
384 KB |
1_19.txt |
AC |
21 ms |
384 KB |
1_20.txt |
AC |
19 ms |
384 KB |
1_21.txt |
AC |
19 ms |
384 KB |
1_22.txt |
AC |
19 ms |
384 KB |
1_23.txt |
AC |
19 ms |
384 KB |
1_24.txt |
AC |
1 ms |
256 KB |
1_25.txt |
AC |
2 ms |
256 KB |
1_26.txt |
AC |
1 ms |
256 KB |
1_27.txt |
AC |
2 ms |
256 KB |
1_28.txt |
AC |
1 ms |
256 KB |
1_29.txt |
AC |
2 ms |
256 KB |
1_30.txt |
AC |
1 ms |
256 KB |
1_31.txt |
AC |
2 ms |
256 KB |