Submission #20111

#TimeUsernameProblemLanguageResultExecution timeMemory
20111gs14004팔찌 (kriii4_V)C++14
6 / 100
1000 ms13440 KiB
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <limits.h> #include <stack> #include <queue> #include <map> #include <set> #include <algorithm> #include <string> #include <functional> #include <vector> #include <numeric> #include <deque> #include <utility> #include <bitset> #include <iostream> using namespace std; typedef long long lint; typedef long double llf; typedef pair<int, int> pi; const int mod = 1e9 + 7; lint ipow(lint x, lint p){ lint ret = 1, piv = x % mod; while(p){ if(p&1) ret *= piv; piv *= piv; ret %= mod; piv %= mod; p >>= 1; } return ret; } int dp[1000005]; int phi(int x){ if(~dp[x]) return dp[x]; int tmp = x; lint ret = x; set<int> s; int cnt = 0; for(int i=2; i*i<=x; i++){ if(x % i == 0) s.insert(i); while(x % i == 0){ x /= i; } } if(x > 1) s.insert(x); for(auto &i : s){ ret *= (i-1); ret /= i; } return dp[tmp] = ret; } int n, k; lint kpow[1000005]; int solve(int n, int k){ lint ret = 0; for(int i=1; i*i<=n; i++){ if(n%i == 0){ ret += kpow[i] * phi(n/i) % mod; if(i*i!=n) ret += kpow[n/i] * phi(i) % mod; ret %= mod; } } ret *= ipow(n, mod - 2); ret %= mod; return ret; } int main(){ memset(dp, -1, sizeof(dp)); cin >> n >> k; kpow[0] = 1; for(int i=1; i<=n; i++){ kpow[i] = kpow[i-1] * k % mod; } lint ret = 2; for(int i=1; i<=n; i++){ ret += solve(i, k); ret %= mod; if(i%2 == 0) ret += (1ll * (k+1) * kpow[i/2] % mod) * ((mod + 1) / 2) % mod; else ret += kpow[i/2+1]; ret %= mod; } ret *= (mod + 1) / 2; ret %= mod; cout << ret; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...