HDU2421

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 = A B, where 1 <= A, B <= 1000000, and a 0, a 1, a 2, …, a k-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 = A B = 8, a 0 = 1, a 1 = 2, a 2 = 4, a 3 = 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的所有因子的因子个数的立方和。。。好吧表示描述起来都十分恶心的题目。。

思路准备手打上传。。。



额这题昨天很快就把分解质因数写了,后来就卡壳了,导致失眠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;
}


评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值