POJ 3604 Professor Ben

Professor Ben
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 Na1,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;
}


發佈了73 篇原創文章 · 獲贊 7 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章