Ignatius's puzzle
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8201 Accepted Submission(s): 5689
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".
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
11 100 9999
Sample Output
22 no 43
思路:
利用数学归纳法:
①找到能使f(1)被65整除的a
②假设f(x)能被65整除
③证明f(x+1)也能
利用二项式定理,将f(x+1)展开
f(x+1)=5*( (C13,0)*x^13+(C13,1)*x^12+(C13,2)*x^11+...+(C13,13) )+13*( (C5,0)*x^5+(C5,1)*x^4+(C5,2)*x^3+...+(C5,5) )+k*a*(x+1)
=f(x)+5*( (C13,1)*x^12+(C13,2)*x^11+...+(C13,13) )+13*( (C5,1)*x^4+(C5,2)*x^3+...+(C5,5) )+k*a*1
因为划线部分都能被65整除,所以只要看5*(C13,13)+13*(C5,5)+k*a(即18+a*k)能否被65整除即可,发现f(1)也等于18+a*k
当k%65=0时,18+k*a是永远除不尽65的
当k%65!=0 时,从1开始找a,判断18+k*a是否能除尽65,找到即止,当a==66时,也就是已经找了一个周期了,在找下去也找不到适当的a了。
代码:
#include<iostream>
#include<map>#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int k,a;
while(cin>>k)
{
for(a=1;a<=65;a++)
{
if((18+a*k)%65==0)
{
cout<<a<<endl;
break;
}
}
if(a==66)
cout<<"no"<<endl;
}
return 0;
}
注:
题中65|f(x)是f(x)能被65整除的意思