HDU - 1098 - Ignatius's puzzle (数论 - 费马小定理)

来源:互联网 发布:docker运行windows程序 编辑:程序博客网 时间:2024/05/16 06:01

Ignatius's puzzle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7012    Accepted Submission(s): 4847


Problem Description
Ignatius is poor at math,he falls across a puzzle problem,so he has no choice but to appeal to Eddy. this problem describes that:f(x)=5*x^13+13*x^5+k*a*x,input a nonegative integer k(k<10000),to find the minimal nonegative integer a,make the arbitrary integer x ,65|f(x)if
no exists that a,then print "no".

 

Input
The input contains several test cases. Each test case consists of a nonegative integer k, More details in the Sample Input.
 

Output
The output contains a string "no",if you can't find a,or you should output a line contains the a.More details in the Sample Output.
 

Sample Input
111009999
 

Sample Output
22no43
 

Author
eddy
 






文章参考:点击打开链接

f(x)=5*x^13+13*x^5+k*a*x=x(5*x^12+13*x^4+k*a),这个函数的形式直接就是费马小定理的形式


费马小定理(Fermat Theory)是数论中的一个重要定理,其内容为: 假如p是质数,且Gcd(a,p)=1,那么 a(p-1) ≡1(mod p)。即:假如a是整数,p是质数,且a,p互质(即两者只有一个公约数1),那么a的(p-1)次方除以p的余数恒等于1。


数论四大定理:百度百科(有费马小定理的证明)


对f(x)=x(5*x^12+13*x^4+k*a)用此定理分析:


(1)如果x是65的倍数,那么已经符合65整除f(x)


(2)如果x是5的倍数,只要5*x^12+13*x^4+k*a被13整除即可,去掉13的倍数13*x^4,也即5*x^12+k*a被13整除,由费马小定理,5与13互质,13是质数,所以x^(13-1)模13余1,所以5*x^12模13余5,要使5*x^12+k*a被13整除,k*a必须模13余8(k*a≡8(mod 13))


(3)如果x是13的倍数,类似(2),需要13*x^4+k*a被5整除,由费马小定理类似得到x^4模5余1,所以13*x^4模5余3,k*a必须模5余2(k*a≡2(mod 5))


(4)如果x不含5和13这两个因子,则需要5*x^12+13*x^4+k*a被65整除了,等价于既要被5整除,又要被13整除,就相当于以上(2)(3)两种情况的条件要同时满足,所以有 k*a≡2(mod 5) 并且 k*a≡8(mod 13)


因为题目说对于任意的x都有65能够整除f(x),所以k*a≡2(mod 5) 并且 k*a≡8(mod 13)需要同时成立才行。




AC代码:

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;int main() {int k;while(scanf("%d", &k) != EOF) {int flag = 0;for(int i = 1; i <= 65; i++) {if(i * k % 13 == 8 && i * k % 5 ==2) {printf("%d\n", i);flag = 1;break;}}if(flag == 0) printf("no\n");}return 0;}









1 0
原创粉丝点击