Code:
#include <cstdio> #include <algorithm> #include <cstring> #define ll long long #define setIO(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout) const long long mod = 2147483648; const long long N = 100008; const int maxn = 100009 ; using namespace std; struct M{ int delta; int id; }opt[maxn]; int prime[maxn],tot,vis[maxn],mu[maxn],g[maxn],answer[maxn]; int cmp2(M a,M b){ return a.delta < b.delta; } void Init(){ mu[1] = 1; for(int i=2;i < maxn; ++i) { if(!vis[i]) prime[++tot] = i, mu[i] = -1; for(int j=1;j <= tot && (ll)i * prime[j] <= N; ++j) { vis[i * prime[j]] = 1; if(i % prime[j]==0) { mu[i * prime[j]] = 0; break; } mu[i*prime[j]]=-mu[i]; } } for(int i=1;i<maxn;++i) for(ll j=1;(ll)j*i<=N;++j) g[i*j] += i; for(int i=1;i<maxn;++i) opt[i].delta=g[i],opt[i].id=i; sort(opt+1,opt+maxn,cmp2); } struct BIT{ ll C[maxn]; int lowbit(int t) { return t & (-t); } void update(int x,ll k) { while(x < maxn) { C[x]+=k, C[x]%=mod; x+=lowbit(x); } } ll query(int x){ ll sum=0; while(x>0) sum+=C[x],sum%=mod,x-=lowbit(x); return sum; } }tree; ll work(int n,int m,int p) { if(n>m) swap(n,m); long long sum=0; for(int i=1,j;i <= n;i=j+1) { j=min(n/(n/i),m/(m/i)); sum+=(n/j)*(m/j)*(tree.query(j)-tree.query(i-1)); sum%=mod; } return sum; } struct P{ int n,m,a,id; }node[maxn]; int cmp(P a,P b){ return a.a<b.a; } void oper(int p){ for(int i=1;i*opt[p].id<=N;++i) tree.update(opt[p].id*i,((ll)opt[p].delta*mu[i]+mod)%mod); } int main(){ //setIO("input"); Init(); int T; scanf("%d",&T); for(int i=1;i<=T;++i) scanf("%d%d%d",&node[i].n,&node[i].m,&node[i].a),node[i].id=i; sort(node+1,node+1+T,cmp); int last=1; for(int i=1;i<=T;++i) { int j=last; while(opt[j].delta <= node[i].a) oper(j),++j; last=j; answer[node[i].id]=(int)work(node[i].n,node[i].m,node[i].a); } for(int i=1;i<=T;++i) printf("%d ",(answer[i]+mod)%mod); return 0; }