Time Limit: 5000MS | Memory Limit: 65536K | |
Total Submissions: 7590 | Accepted: 1840 |
Description
Professor Ben is an old stubborn man teaching mathematics in a university. He likes to puzzle his students with perplexing (sometimes boring) problems. Today his task is: for a given integer N, a1,a2, ... ,an are the factors of N, let bi be the number of factors of ai, your job is to find the sum of cubes of all bi. Looking at the confused faces of his students, Prof. Ben explains it with a satisfied smile:
Let's assume N = 4. Then it has three factors 1, 2, and 4. Their numbers of factors are 1, 2 and 3 respectively. So the sum is 1 plus 8 plus 27 which equals 36. So 36 is the answer for N = 4.
Given an integer N, your task is to find the answer.
Input
The first line contains the number the test cases, Q(1 ≤ Q ≤ 500000). Each test case contains an integer N(1 ≤ N ≤ 5000000)
Output
For each test case output the answer in a separate line.
Sample Input
1 4
Sample Output
36
Source
#include<stdio.h> #include<string.h> #include<time.h> #define READ(x) (scanf("%I64d",&x)) #define COUT(x) (printf("%I64d\n",x)) typedef __int64 ll; ll prime[2500]; bool flag[2500]; void init() { ll i,j,num=0; for(i=2;i<2500;i++) { if(!flag[i]) { prime[num++]=i; for(j=i*i;j<2500;j=j+i) flag[j]=true; } } } ll sum(ll n) { return (n*(n+1)/2)*(n*(n+1)/2); } void solve(ll n) { ll i,ans=1,tmp; for(i=0;prime[i]*prime[i]<=n;i++) { tmp=0; if(n%prime[i]==0) { n=n/prime[i]; tmp++; while(n%prime[i]==0) { tmp++; n=n/prime[i]; } ans=ans*sum(tmp+1); } if(n==1) break; } if(n>1) ans=ans*9; COUT(ans); } int main() { ll n,Q; init(); READ(Q); while(Q--) { READ(n); solve(n); } return 0; }