Professor Ben 唯一分解定理:因子的因子個數

題意:一個數N,它的因子爲a1,a2....ai...an,求每一個因子的因子個數的三次方;

例如4的因子1,2,4。1的因子個數爲1,2的因子個數爲2,4的因子個數爲3

結果bns=1^3+2^3+3^3=36;

思路:唯一分解定理(自己去網上了解)求每個素數因子的指數

例如36=2^2*3^2;2的指數是2,意味着有三種組合,2^0,2^1,2^2,

每一種組合能提供(1+0),(1+1),(1+3)個因子,同理可得3^2;

所以答案爲((1+0)^3+(1+1)^3(1+2)^3)*((1+0)^3+(1+1)^3(1+2)^3);

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef long long ll;
const int N=1e4+5;
int tot=0,ans[N];
bool vis[N];
ll power[25];

void primer()
{
    memset(vis,true,sizeof(vis));
    for(int i=2;i<N;i++)
    {
        if(vis[i]) ans[++tot]=i;
        for(int j=1;(j<=tot)&&(ans[j]*i<N);++j)
        {
            vis[ans[j]*i]=false;
            if(i%ans[j]==0) break;
        }
    }
}

void powe()
{
    for(int i=1;i<23;i++)
        for(int j=0;j<=i;j++)
        power[i]+=(1+j)*(1+j)*(1+j);
}

ll pre(int n)
{
    ll bns=1;
    for(int i=1;ans[i]*ans[i]<=n;i++)
    {
        int cnt=0;
        while(n%ans[i]==0){
            n/=ans[i];
            cnt++;
        }
        if(cnt>0) bns*=power[cnt];
    }
    if(n>1)  bns*=9;
    return bns;
}

int main()
{
    powe();
    primer();
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        printf("%lld\n",pre(n));
    }
    return 0;
}

題目:

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, ... ,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

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