Time Limit: 5000MS | Memory Limit: 65536K | |
Total Submissions: 8995 | Accepted: 2298 |
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, ... ,anare 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
题意:给一个数,求这个数的因数的因数个数的立方和,比如6的因子有1 2 3 6,1的因子数为1,2的为2,3的为2,6的为4,所以答案就是1^3+2^3+3^3+4^3=81
我是通过找规律找到答案的,如f(6)=f(2)*f(3)=81,而f(2)=f(3)=9,即当m,互质时f(m*n)=f(m)*f(n),当m可化为n^p时,f(m)=f(n^p)=(1^3+2^3+3^3+……+p^3),如f(4)=f(2^2)=1^3+2^3+3^3,f(18)=f(3^2*2)=f(3^2)*f(2)=36*9,当n为质数时,f(n)=9,结论就很明显了,就是一个唯一分解
详细推导过程可参考:http://blog.csdn.net/famousdt/article/details/7285382
#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<cmath>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
#define pi acos(-1.0)
#define eps 1e-10
#define pf printf
#define sf scanf
#define lson rt<<1,l,m
#define rson rt<<1|1,m+1,r
#define e tree[rt]
#define _s second
#define _f first
#define all(x) (x).begin,(x).end
#define mem(i,a) memset(i,a,sizeof i)
#define for0(i,a) for(int (i)=0;(i)<(a);(i)++)
#define for1(i,a) for(int (i)=1;(i)<=(a);(i)++)
#define mi ((l+r)>>1)
#define sqr(x) ((x)*(x))
const int inf=0x3f3f3f3f;
const int Max=3e3;
int m,n,p[Max/5];
ll a[200],ans;
bool vis[Max+1];
void init()//打立方表,2^23>5e6,
{
a[1]=1;
for(int i=2;i<=23;i++)
a[i]=a[i-1]+(ll)i*i*i;
}
void prime()//打素数表到3e3
{
mem(vis,0);
p[0]=0;
vis[1]=1;
for(int i=2;i<=Max;i++)
{
if(!vis[i])p[++p[0]]=i;
for(int j=1;j<=p[0]&&(ll)i*p[j]<=Max;j++)
{
vis[i*p[j]]=1;
if(!(i%p[j]))break;
}
}
}
void solve()//唯一分解
{
for(int i=1;i<=p[0]&&(ll)p[i]*p[i]<=n;i++)
{
int num=0;
while(!(n%p[i]))
num++,n/=p[i];
if(num>1)
ans*=a[num+1];
else if(num)
ans*=9;
}
if(n>1)ans*=9;
}
int main()
{
init();
prime();
sf("%d",&m);
while(m--)
{
ans=1;
sf("%d",&n);
solve();
pf("%lld\n",ans);
}
return 0;
}