quickly calc pow(i, n) since i in [1~n]
Posted liuweimingcprogram
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了quickly calc pow(i, n) since i in [1~n]相关的知识,希望对你有一定的参考价值。
#include <bits/stdc++.h> using namespace std; #define inf (0x3f3f3f3f) typedef long long int LL; const int mod = 1e9 + 7; const int maxn = 13000000 + 2; LL f[maxn]; int prime[maxn]; bool check[maxn]; int n; int qp(int a, int b) { LL result = 1; LL base = a; while (b) { if (b & 1) { result *= base; result %= mod; } b >>= 1; base *= base; base %= mod; } return result; } void init_prime() { f[1] = 1; int total = 0; for (int i = 2; i <= n; ++i) { if (!check[i]) { prime[++total] = i; f[i] = qp(i, n); } for (int j = 1; j <= total; ++j) { if (i * prime[j] > n) break; check[i * prime[j]] = true; f[i * prime[j]] = f[prime[j]] * f[i] % mod; if (i % prime[j] == 0) break; } } } void work() { scanf("%d ", &n); init_prime(); LL result = 0; for (int i = 1; i <= n; ++i) { result ^= f[i]; } printf("%lld ", result); } int main(int argc, char *argv[]) { // freopen("data.txt", "r", stdin); work(); return 0; }
https://ac.nowcoder.com/acm/contest/392/C
以上是关于quickly calc pow(i, n) since i in [1~n]的主要内容,如果未能解决你的问题,请参考以下文章