数论结论题。。。就是1-n+1的lcm除以n+1。。。。不知道结论怎么做?----没法做。。。
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int maxn = 1000005; const int N = 1000000; const int mod = 1e9+7; int val[maxn]; LL f[maxn]; LL g[maxn]; int p[maxn]; LL powmod(LL a, LL b) { LL res = 1, base = a; while(b) { if(b % 2) res = res * base % mod; base = base * base % mod; b /= 2; } return res; } void init() { for(int i = 2; i < maxn; i++) if(p[i] == 0) for(int j = i + i; j < maxn; j += i) p[j] = 1; for(int i = 2; i < maxn; i++) if(p[i] == 0) for(LL j = (LL)i; j < maxn; j *= i) val[j] = i; f[1] = 1; for(int i = 2; i < maxn; i++) if(val[i]) f[i] = f[i-1] * val[i] % mod; else f[i] = f[i-1]; for(int i = 1; i <= N; i++) g[i] = f[i+1] * powmod(i+1, mod-2) % mod; } int main() { init(); int _; scanf("%d", &_); while(_--) { int x; scanf("%d", &x); printf("%lld\n", g[x]); } return 0; }