1.3
补个BC。
HDU 5608 function
题解这么说。复杂度不会。
1 #include <iostream> 2 #include <cstdio> 3 #include <map> 4 using namespace std; 5 typedef long long LL; 6 const LL mod = 1e9 + 7; 7 const LL maxn = 1e6 + 10; 8 map<LL,LL> M; 9 LL t[maxn]; 10 11 LL S1(LL n) 12 { 13 LL ret = n * ( n + 1 ) % mod * ( 2 * n % mod + 1 ) % mod * 166666668LL % mod; 14 ret = ( ret - 3 * n % mod * ( n + 1 ) % mod * 500000004LL % mod + mod ) % mod; 15 ret = ( ret + 2 * n ) % mod; 16 return ret; 17 } 18 19 LL S2(LL n) 20 { 21 if(n < maxn) return t[n]; 22 if(M.find(n) != M.end()) return M[n]; 23 LL ret = S1(n); 24 for(LL i = 2; i <= n; i++) 25 { 26 LL r = n / ( n / i ); 27 ret = (ret - S2(n/i) * ( r - i + 1 ) % mod + mod) % mod; 28 i = r; 29 } 30 return M[n] = ret; 31 } 32 33 void pre() 34 { 35 for(LL i = 1; i < maxn; i++) t[i] = (i - 1) * (i - 2) % mod; 36 for(int i = 1; i < maxn; i++) 37 for(int j = 2; i * j < maxn; j++) 38 t[i*j] = (t[i*j] - t[i] + mod) % mod; 39 for(int i = 1; i < maxn; i++) t[i] = ( t[i] + t[i-1] ) % mod; 40 return; 41 } 42 43 int main(void) 44 { 45 pre(); 46 int T; 47 scanf("%d", &T); 48 while(T--) 49 { 50 LL n; 51 scanf("%I64d", &n); 52 printf("%I64d\n", S2(n)); 53 } 54 return 0; 55 }
Aguin
时间: 2024-10-11 11:12:10