Deciphering PasswordTime Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1044 Accepted Submission(s): 241
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
|
题意:给出一个数A^B,求这个数分解成定理一的形势后,(连乘(1^3+2^3+...+(ei+1)^3) )%10007
题目的意思很容易让人误解成因子个数M(1^3+2^3+...+N^3)%10007
定理一:任何一个大于2的数都可以分解成 num=p1^e1*p2^e2*p3^e3*...*pn^en,这个数的因子个数为(e1+1)*(e2+1)*...*(en+1)
定理二:1^3+2^3+...+N^3=((n*(n+1)/2))^2
具体思路看代码:
#include<iostream>
using namespace std;
#define N 1010
bool is[N];
__int64 res[N]; //质因数分解的结果
short prim[N]; //素数打表
int main()
{
memset(is,true,sizeof(is));
__int64 i,j,a,b;
for(i=2;(i<<1)<1001;i++) //素数打表
{
for(j=2;i*j<1001;j++)
is[j*i]=false;
}
int sum=0;
for(i=2;i<=1000;i++)
if(is[i])
prim[sum++]=i;
int cnt=0;
while(scanf("%I64d%I64d",&a,&b)!=EOF)
{
b%=10007;
printf("Case %d: ",++cnt);
int total=0;
memset(res,0,sizeof(res));
for(i=0;a!=1&&i<sum;i++) //质因数分解
{
if(a%prim[i]==0)
{
while(a%prim[i]==0)
{
res[total]++;
a/=prim[i];
}
total++;
}
}
if(a!=1)
res[total++]=1;
__int64 ans=1;
for(i=0;i<total;i++)
{
__int64 s;
s=(((b*res[i]+1)*(b*res[i]+2))/2)%10007; //1^3+2^3+....+(ei+1)^3
s*=s;
ans=(ans*s)%10007;
}
printf("%I64d\n",ans);
}
return 0;
}