#include using namespace std; using i64 = long long; static long long N, B; struct SmallData { long long total_contrib; long long total_pairs; vector uvals; } small_data; static vector mu; // u(m,s)=2(m+s)(2m+s) inline __int128 calc_u128(long long m, long long s) { __int128 x = m+s; __int128 y = 2*m + s; __int128 val = 2 * x * y; return val; } inline long long calc_u(long long m, long long s) { __int128 val = calc_u128(m,s); if(val > (__int128)LLONG_MAX) return LLONG_MAX; return (long long)val; } long long enumerate_small_store() { long long ans = 0; long long t=(long long)B/2.0; long long limit = (long long)(floor(powl(t,0.5L)))+2; vector vals; for (long long m=1; m<=limit; m++) { long long low=1,high=1000000000; while(low>1; __int128 val = calc_u128(m,mid); if(val<=B) low=mid; else high=mid-1; } long long Smax = low; if (Smax < 1) continue; for (long long s=1; s<=Smax; s++) { long long uv = calc_u(m,s); long long contrib = (long long)(N/uv); ans += contrib; vals.push_back(uv); } } sort(vals.begin(), vals.end()); small_data.total_contrib = ans; small_data.total_pairs = (long long)vals.size(); small_data.uvals = move(vals); return ans; } long long count_pairs_U_lessEqB(long long U) { if(U<=0) return 0; auto it = upper_bound(small_data.uvals.begin(), small_data.uvals.end(), U); return (long long)(it - small_data.uvals.begin()); } long long count_pairs_anyU(long long U) { if(U<=B) { return count_pairs_U_lessEqB(U); } long long tt = (long long)U/2.0; long long limit = (long long)(floor(powl(tt,0.5L)))+2; long long cnt=0; for (long long m=1; m<=limit; m++) { long long low=1,high=1000000000; while(low>1; __int128 val = calc_u128(m,mid); if(val<=U) low=mid; else high=mid-1; } long long Smax = low; if(Smax>=1) cnt+=Smax; } return cnt; } void linear_sieve_mu(int maxd) { mu.clear(); mu.resize(maxd+1,0); vector minf(maxd+1,0), primes; mu[1]=1; for (int i=2;i<=maxd;i++){ if(!minf[i]){ minf[i]=i; primes.push_back(i); mu[i]=-1; } for (auto p : primes) { if((i64)p*i>maxd) break; minf[p*i]=p; if(i%p==0) { mu[p*i]=0; break; } else { mu[p*i]=-mu[i]; } } } } inline int mu_of_d(i64 d) { if(d<(int)mu.size()) return mu[(int)d]; // 对于本问题应该不会越界 // 万一发生,也可以退化为因子分解 // 这里直接因子分解 int factors=0; i64 x=d; for(i64 p=2;p*p<=x;p++){ if(x%p==0) { factors++; x/=p; if(x%p==0)return 0; } } if(x>1) factors++; return (factors%2==0)?1:-1; } // G函数 i64 G_func(i64 n){ if(n<12)return 0LL; i64 ans=0; long long nd=(long long)n; long long V=cbrt(nd); i64 B2=n/V; long long tmp=4.0L*B2+1.0L; long long sq=sqrtl(tmp); long long X=(sq-3.0L)/4.0L; //i64 X=(i64)floor(Xd); { for(i64 x=1;x<=X;x++){ long long temp=(long long)(x*x+2*B2); long long YY=sqrtl(temp); long long Y=(YY-3*x)/2.0L; //i64 Y=(i64)floor(Yd); if(Y<1) continue; for(i64 y=1;y<=Y;y++){ i64 val=2*(x+y)*(2*x+y); ans+=n/val; } } } vector cnt(V+1,0); for(i64 i=1;i<=V;i++){ i64 U=n/i; long long tmp2=(long long)(4*U+1); long long sq2=sqrtl(tmp2); long long X2=(sq2-3)/4.0L; //i64 X2=(i64)floor(X2d); for(i64 x=1;x<=X2;x++){ long long tt=(long long)(x*x+2*U); long long yyy=sqrtl(tt); long long Y2d=(yyy-3*x)/2.0L; //i64 Y2=(i64)floor(Y2d); //if(Y2>=1) cnt[i]+=Y2d; } } for(i64 i=1;i>N; { i64 maxd=(i64)(floorl(sqrtl((long long)N)))+10; if(maxd<1) maxd=1; if(maxd>10000000) maxd=10000000; //可根据N大小适当调整上限 linear_sieve_mu((int)maxd); } // 枚举u≤B // 验证给定值 G(10000)=9696 f(10000)=4858 // 本程序不额外输出验证,只输出f(N)结果 i64 result = f_func(N); cout<