hdu 2421 分解质因子
2015-08-05 11:50
225 查看
Deciphering Password
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768K (Java/Others)
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
定理一:任何一个大于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> #include <stdio.h> #include <string.h> using namespace std; const int maxn=1010; const int mod=10007; bool vis[maxn]; int p[170]; int cnt; void unit() { memset(vis,0,sizeof(vis)); cnt=0; for(int i=2;i<=maxn;i++) { if(!vis[i]) { p[cnt++]=i; for(int j=i+i;j<=maxn;j+=i) vis[j]=1; } } } int main() { int a,b; unit(); long long ans; int cas=1;long long count; while(scanf("%d%d",&a,&b)!=EOF) { ans=1; for(int i=0;i<cnt;i++) { count=0; if(a%p[i]==0) { while(a%p[i]==0) { count++; a/=p[i]; } } count=(count*b+1)%mod; count=(count*(count+1)/2)%mod; ans=ans*(count*count%mod)%mod; if(a==1) break; } if(a!=1) { count=(b+1)%mod; count=count*(count+1)/2%mod; ans=ans*(count*count%mod)%mod; } printf("Case %d: %I64d\n",cas++,ans); } return 0; }
相关文章推荐
- MongoDB Sharding实践
- DEDECMS系统分页标签自定义二次开发实例
- 点9图的说明
- VS2010 C#中调用matlab2014a生成的dll的几个问题
- Android SDK NDK API文档等下载地址
- 【CSAPP】《深入理解计算机系统》读书笔记
- LBP特征算法
- Elasticsearch+Logstash+Kibana教程
- 1234
- iOS Navigation自定义设置Item
- php中防盗链使用.htaccess
- 初学git:用git bash往github push代码
- 可伸缩系统的架构经验
- KMP算法
- POST与GET的区别及RESTful
- laravel错误处理...app/storage/sessions...failed to open stream: Permission denied
- css3背景色渐变
- 从AsyncTask中获取数据的问题
- php 字符串截取函数
- 初学git:用git bash往github push代码