已知 f(n)=∑0<=i<n∑0<=j<n[ij(modn)≠0]
求 g(n)=∑m|nf(m) , n<=109
f(n)=n2−∑i∑j[ij(modn)=0]=n2−∑d|nϕ(n/d)d
g(n)=∑m|nf(m)=∑m|n[m2−∑d|mϕ(m/d)d]
后面部分交换求和顺序就是 ∑d|nd∑md|ndϕ(m/d)=∑d|nd∗nd=n∑d|n=nτ(n)
最后 g(n)=∑m|n(m2−n)
然后这题 O(sqrt(n)) 过不去,所以要预处理质数表
n=∏i=1npkii
则
g(n)=∏i=1n1−p2(ai+1)i1−p2i−n∏i=1n(ki+1)
#include
#include
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector
#define pi pair
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case %d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<
#define PRi2D(a,n,m) For(i,n) { \
For(j,m-1) cout<' ';\
cout<long long ll;
typedef unsigned long long ull;
int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
#define MAXN (1000000)
int n,p[MAXN],tot;
bool b[MAXN]={0};
void make_prime(int n)
{
tot=0;
Fork(i,2,n)
{
if (!b[i]) p[++tot]=i;
For(j,tot)
{
if (i*p[j]>n) break;
b[i*p[j]]=1;
if (i%p[j]==0) break;
}
}
}
int main()
{
// freopen("hdu5528.in","r",stdin);
// freopen(".out","w",stdout);
make_prime((int)sqrt(1e9+0.5) );
int T=read();
while(T--) {
ll n;
ll ans;
ans=1;
n=read();
ll tou=n; //nh(n)
For(i,tot) {
int t=p[i];
if (t*t>n) break;
if (n%t) continue;
int cnt=1;
ll mul = t;
while(n%t==0) ++cnt,mul*=t,n/=t;
tou*=cnt;
ll a=(mul-1)/(t-1),b=mul+1,c=t+1;
//ans=a*b/c; 写法1
//ans*=(a/c)*(b/c)*c+a%c*(b/c)+b%c*(a/c); 写法1的防溢出
if (a%c==0) ans*=a/c*b; //这个更直观
else ans*=b/c*a;
}
if (n>1) {
tou*=2;
ans*=(1+n*n);
}
cout<return 0;
}