标签:tar mit cin private name ase com enc col
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
这个题的题意就是求n=a的b次方,数n的各个质因数的立方和;题目给出的a,b范围是100万,所以就要采取特殊的办法了;
这个:质数的N次方会有N+1个因子,大家知道吧(为什么呢,自己慢慢体会);然后这个n就可以分解为多个质数的次方的
乘积;比如f(n)=f(c^x*d^y); 原本题意是各个质因数的立方和其实就等于1的立方和加到n的因子个数的立方和;这里给出公式是
(n*(n+1)/2)^2; 那么因为f(n)=f(c^x*d^y);==1到c^x的立方*1到d^y的因子个数立方和;自己慢慢体会qaq
代码
#include <iostream> #include <cmath> #include <cstring> #include <cstdio> using namespace std; #define mod 10007 int p[100010]; int prim[100010]; int len=0; void isp() //素数筛 { memset(p,0,sizeof(p)); p[0]=1;p[1]=1;p[2]=0; for(int i=0;i<10000;i++) { if(p[i]) continue; for(int j=i;j*i<10000;j++) { p[i*j]=1; } prim[len++]=i; } } int main() { isp(); long long cur=1; long long ans=1; long long a,b; while(cin>>a>>b) { ans=1; for(int i=0;prim[i]*prim[i]<=a;i++) { long long sum=1; int j=0; if(a%prim[i]==0) { while(a%prim[i]==0) { a/=prim[i]; j++; } sum=(b*j+1)*(b*j+2)/2%mod; sum*=sum; ans=ans*sum%mod; } } if(a>1) { long long sum=1; sum=(b+1)*(b+2)/2%mod; sum*=sum; ans=ans*sum%mod; } printf("Case %lld: %lld\n",cur++,ans); } return 0; }
标签:tar mit cin private name ase com enc col
原文地址:https://www.cnblogs.com/xiechenxi/p/8987961.html