您的位置:首页 > 其它

HDU 2421 Deciphering Password 公式推导

2015-08-28 09:29 477 查看


Deciphering Password

Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1964 Accepted Submission(s): 489



Problem Description

Xiaoming has just come up with a new way for encryption, by calculating the key from a publicly viewable number in the following way:

Let the public key N = AB, where 1 <= A, B <= 1000000, and a0, a1, a2, …, ak-1 be the factors of N, then the private key M is calculated by summing the cube of number of factors of all ais. For example,
if A is 2 and B is 3, then N = AB = 8, a0 = 1, a1 = 2, a2 = 4, a3 = 8, so the value of M is 1 + 8 + 27 + 64 = 100.

However, contrary to what Xiaoming believes, this encryption scheme is extremely vulnerable. Can you write a program to prove it?



Input

There are multiple test cases in the input file. Each test case starts with two integers A, and B. (1 <= A, B <= 1000000). Input ends with End-of-File.

Note: There are about 50000 test cases in the input file. Please optimize your algorithm to ensure that it can finish within the given time limit.



Output

For each test case, output the value of M (mod 10007) in the format as indicated in the sample output.



Sample Input

2 2
1 1
4 7




Sample Output

Case 1: 36
Case 2: 1
Case 3: 4393


题意:告诉a,b求a^b得到数N,对于数N,求出N的所有因子,1, n1, n2, n3, n4, .......nk, N,对于这些因子,他们分别拥有的因子个数为1, m1, m2, m3, m4,......mk,k+2.求出这些因子的因子个数的立方和。

分析:对于一个数字大于1的数字N,可以分解N=p1^x1+p2^x2+p3^x3.....pn^xn的形式,这个数N总共有(x1+1)*(x2+1)*(x3+1)...(xn+1)个因数,N的所有组成因数是由x1,x2,x3...xn中任意取几个组合而成,因数T^3=(p1^a1^3)*(p2^a2^3)*(p3^a3^3)....(pn^an^3)。所有因子的三次方和可以写成(1^3+2^3+3^3....(x1+1)^3)*(1^3+2^3+3^3....(x1+1)^3)*(1^3+2^3+3^3....(x2+1)^3)*(1^3+2^3+3^3....(x3+1)^3).......*(1^3+2^3+3^3....(xn+1)^3)
,(1^3+2^3+3^3....(n+1)^3)=((n+1)*n/2)^2

#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
int pri[100009];
int vis[100009];
int cnt;
typedef __int64 ll;

using namespace std;

void init()
{
    cnt=0;
    for(int i=2;i<=100009;i++)
        {
            if(vis[i]==0) pri[cnt++]=i;
            for(int j=0;j<cnt && i*pri[j]<=100009;j++)
            {
                vis[i*pri[j]]=1;
                if(i%pri[j]==0) break;
            }
        }
}

ll res[10009];

int main()
{
    ll a,b;
    int ca=1;
    init();
    while(~scanf("%I64d%I64d",&a,&b))
    {
        printf("Case %d: ",ca++);

        int tot=0;
        memset(res,0,sizeof res);

        for(int i=0;i<cnt && pri[i]*pri[i]<=a;i++)
        {
            if(a%pri[i]==0)
            {
                a/=pri[i];
                res[tot]++;
                while(a%pri[i]==0) {a/=pri[i];res[tot]++;}
                tot++;
            }
        }
        if(a>1)
            res[tot++]++;

        ll ans=1;
        ll tmp=1;

        for(int i=0;i<tot;i++)
        {
            tmp=(res[i]*b+1)*(res[i]*b+2)/2;
            tmp%=10007;
            tmp=tmp*tmp%10007;
            ans=ans*tmp%10007;
        }
        printf("%I64d\n",ans);
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: