Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4059
A high pass rate in the competition, but the principle of rejection is not very good ..
Reference http://blog.csdn.net/acm_cxlove/article/details/7434864
1. Calculate the inverse element P = 1e9 + 7 is the prime number, so the inverse element of a % P obtained from a ^ (p-1) % P with the remainder of 1 is a ^ (P-2)
2. segma (I ^ K) can obtain the summation formula by derivation. For details, see http://blog.csdn.net/acm_cxlove/article/details/7434864.
3. The code is pretty well written in the anti-spoofing principle.
# Include <cstdio> # include <cstring> # include <iostream> # include <algorithm> # include <set> # include <cmath> # include <vector> using namespace STD; # define ll long # define in (s) freopen (S, "r", stdin) # define out (s) freopen (S, "W", stdout) const int mod = 1000000007; const int n = 10005; const int M = 10050; ll N, Thr; // reverse element vector of thr 30 <int> FAC; bool is [N]; int PRM [m]; int getprm (int n) {int I, j, k = 0; int S, E = (INT) (SQRT (0.0 + n) + 1); memset (is, 1, sizeof (is); PRM [k ++] = 2; is [0] = is [1] = 0; for (I = 4; I <n; I + = 2) is [I] = 0; for (I = 3; I <E; I + = 2) if (is [I]) {PRM [k ++] = I; for (S = I * 2, j = I * I; j <n; j + = s) is [J] = 0; // because J is an odd number, it is an even number after I is an odd number and does not need to be processed!} For (; I <n; I + = 2) if (is [I]) PRM [k ++] = I; return K; // returns the number of prime numbers} ll qmod (ll x, ll t) {ll ret = 1, base = x; while (t) {If (T & 1) ret = (Ret * base) % MOD; base = (base * base) % MOD; T/= 2;} return ret;} ll sum (ll x) {ll ret = 1; ret = (Ret * X) % MOD; ret = (Ret * (x + 1) % MOD; ret = (Ret * (2 * x + 1) % mod) % MOD; ret = (3 * x * X) % mod + (3 * X) % mod-1 + mod) % mod * RET) % MOD; Return (Ret * THR) % MOD;} inline ll four (ll x) {return (X % mod) * x % mod) * X % MOD;} ll DFS (INT cur, ll TMP) // refresh principle {ll ret = 0, F; For (INT I = cur; I <FAC. size (); I ++) {f = FAC [I]; ret = (Ret + (sum (TMP/F) * Four (F) % mod) % MOD; ret = (ret-DFS (I + 1, TMP/F) * Four (F) % mod + mod) % MOD;} return ret % MOD ;} int main () {// In ("hdu4059.txt"); int ncase; ll S1, S2; scanf ("% d", & ncase ); int prmnum = getprm (N-1); thr = qmod (30, mod-2); While (ncase --) {scanf ("% i64d", & N ); // int Sn = (INT) SQRT (n); FAC. clear (); ll tmp = N; For (INT I = 0; I <prmnum & PRM [I] <= TMP; I ++) {If (TMP % PRM [I] = 0) {FAC. push_back (PRM [I]); While (TMP % PRM [I] = 0) tmp/= PRM [I];} // while (TMP % PRM [I] = 0) FAC. push_back (PRM [I]), TMP/= PRM [I]; If (TMP! = 1) FAC. push_back (TMP); // cout <"Fuck =" <sum (n) <Endl; printf ("% i64d \ n", (sum (N) -DFS (0, n) + mod) % mod);} return 0 ;}
HDU 4059 number theory + high power sum + refresh Principle