HDU2421

来源:互联网 发布:淘宝怎么搜阿普唑仑 编辑:程序博客网 时间:2024/06/05 11:16

Deciphering Password

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1424    Accepted Submission(s): 356


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 21 14 7
 

Sample Output
Case 1: 36Case 2: 1Case 3: 4393

题意:求A^B的所有因子的因子个数的立方和。。。好吧表示描述起来都十分恶心的题目。。

思路准备手打上传。。。



额这题昨天很快就把分解质因数写了,后来就卡壳了,导致失眠o(╯□╰)o。。也许在大牛看起来很脑残- -但是大牛的解题报告跳跃性实在略大,故自己和学弟一起证明了一下,大致如此。。字矬,数学素养太低。。请勿吐槽。。谢谢,将就着看吧。。

#include<cstdio>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>using namespace std;const int mod=10007;bool is_prime[1005];int  prime[1005];long long res[1005];void dabiao(){    is_prime[0]=is_prime[1]=1;    for(int i=2;i<1000;i++)    {        is_prime[i]=0;    }    for(int i=0;i<1000;i++)    {        if(is_prime[i]==1)        {            continue;        }        for(int j=2*i;j<1000;j+=i)        {            is_prime[j]=1;        }    }}int main(){    dabiao();    int k=0;    for(int i=0;i<1000;i++)    {        if(is_prime[i]==0)        {            prime[k++]=i;        }    }int a,b; int cas=1;   while(cin>>a>>b)    {        b%=mod;        int sum=0;        memset(res,0,sizeof(res));        for(int i=0;a!=1&&i<k;i++)        {            if(a%prime[i]==0)            {                 while(a%prime[i]==0)                {                    res[sum]++;                    a/=prime[i];                }                sum++;            }        }//将A先分解素因数,res[i]表示可以写成prime[i]的多少次幂则N=A^B=(p0)^(res0*b)*(p1)^(res1*b)...*(pn)^(resn*b)        if(a!=1)        {            res[sum++]=1;//如果是素数。。那么就是1呗。        }        long long ans=1;        long long s;        for(int i=0;i<sum;i++)        {            s=((b*res[i]+1)*(b*res[i]+2)/2)%mod;//则N的素因子个数为(res0*b+1),(res1*b+1)...(resn*b+1)再求立方和就O了。             s=(s*s)%mod;             ans=(ans*s)%mod;            //cout<<res[i]<<endl;        }         printf("Case %d: %I64d\n",cas++,ans);        //cout<<ans<<endl;    }    return 0;}


0 0
原创粉丝点击