Professor Ben POJ - 3604


Professor Ben  POJ - 3604


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 integerN, a1,a2, ... ,an are the factors ofN, let bi be the number of factors ofai, your job is to find the sum of cubes of allbi. 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 forN = 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 integerN(1 ≤ N ≤ 5000000)

Output

For each test case output the answer in a separate line.

Sample Input 1
4

Sample Output 36

题意:  给一个数,求他的每一个因子的因子的个数^3 的和。
思路:  比赛的时候没想出来,首先直接遍历用欧拉函数绝对会超时。看别人博客的思路,结果还WA 了好几发...... 对于一个数n : 由唯一分解定理 n= p1^a1*p2^a2*p3^a3...... 那么n 的因子的个数为  (1+a1)*(1+a2)*(1+a3)...... 而我们要知道的是  n 的因子,那么就有 b1= p1^x1*p2^x2*p3^x3... ; b2=... ; ....... b1 的因子个数有(1+x1)*(1+x2)*(1+x3)*...... b2...... ...... 最后求他们的立方 然后累加,其实这个公式可以合并,结果得到一个简单的式子 (a1+1)*(a1+1)*(a1+2)*(a1+2)*(a2+1)*(a2+1)*......
具体合并分析:    以两个因子为例:n =  p1^a1*p2^a2;设f(x)  为  因子个数的立方。 转为公式:  g(p1^a1*p2^a2)=f(p1^a1*p2^a2)+f(p1^(a1-1)*p2^a2)+f(p1^...)+...+f(p1^0*p2*a2)+....f(...+ f(p1^0*p2^0) 又对于  f(x)  有一个性质:  f(x)  为积性函数,即 f(x*y)=f(x)*f(y); 那么就可以合并了: g(p1^a1*p2^a2)  =  (f(a1^m)+f(a1^m-1)+...+f(a1^0))*(f(b1^m)+...+f(b1^0))     对于f( a^b )=(b+1)^3;      原式就变成了  (1^3+...+(a1+1)^3)*(1^3+...+(a2+1)^3) 又 立方和公式为 [(x * (x + 1)) / 2] ^ 2; 就得出了 公式  a1*(a1+1)*(a1)*(a1+1)/4*a2*a2*(a2+1)*(a2+1)...

#pragma comment(linker, "/STACK:1024000000,1024000000")
//#include <bits/stdc++.h>
#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#define maxn 5055000
#define INF 0x3f3f3f3f
#define eps 1e-8
#define MOD 1000000007
#define ll long long
using namespace std;

int len;
int pri[maxn];
bool vis[maxn];
void init()
{
    len=0;
    memset(vis,0,sizeof vis);
    for(int i=2;i<3010;i++)
    {
        if(!vis[i])
            pri[len++]=i;
        for(int j=0;j<len&&i*pri[j]<3010;j++)
        {
            vis[i*pri[j]]=1;
            if(i%pri[j]==0) break;
        }
    }
}
ll solve(int x)
{
    return x*x*(x+1)*(x+1)/4;
}
int main()
{
    init();
    int T;
    scanf("%d",&T);
    int n;
    while(T--)
    {
        scanf("%d",&n);
        ll ans=1;
        int x=0;
        if(n==1)    {  puts("1");continue; }
        for(int i=0;i<len&&pri[i]<=n;i++)   //分解质因子
        {
            if(n%pri[i]==0)
            {
                int x=1;
                while(n%pri[i]==0)
                {
                    x++;
                    n/=pri[i];
                }
                ans*=solve(x);
            }
        }
        if(n>1)  ans*=solve(2);
            printf("%lld\n",ans);
    }
    return 0;
}


 



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值