这道题可以说主要是解决数学问题,代码是简单的。看到网上用人说用费马小定理,不过我数学不好,数论更不好,不过好在数学归纳法可以帮我们解决这一问题。其实这道题要求对任意的x能使65整除f(x),也暗示了用归纳法证明当f(n)成立时,f(n+1)成立,这样我们就只需求使f(1)满足条件的最小a。
简单证明如下:
如何对任意x都有65整除f(x),那么f(1)一定要成立(并且x等于0时,一定成立,由于f(x)中x的指数均为奇数,所以正数成立,对应的负数一定成立)。假设我们已经找到使f(1)=18+a*k满足条件的a了,即当n=1是,65|f(1);假设当n=x时,有f(x)=5*x^13+13*x^5+k*a*x满足条件,f(x+1)=5*(x+1)^13+13*(x+1)^5+k*a*(x+1),展开二项式,得f(x+1)=5*( C(13,0)+C(13,1)*x+……+C(13,13)*x^13 ) + 13*( C(5,0)+C(5,1)*x+……+C5,5)*x^5 ) + k*a*(x+1),可以得f(x+1)=f(x)+5(C(13,1)*x+……+C(13,12)*x^12 ) + 13*(C(5,1)*x+……+C(5,4)*x^4 ) + f(1),由于5(C(13,1)*x+……+C(13,12)*x^12 ) + 13*(C(5,1)*x+……+C(5,4)*x^4 )一定能被65整除(由于5*13(C(12,1)*x+……+C(12,12)*x^12 )和 13*5*(C(4,1)*x+……+C(4,4)*x^4 )),f(1),f(x)也能被65整除,即f(x+1)能被65整除。综上,对任意n有65|f(x)。
这样我们只要找到满足条件的f(1)即可,即a*k%65==47,a从1到65。
附上代码(G++):
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int a,k;
while(cin>>k)
{
for(a=1;a<66;a++)
{
if(k*a%65==47)
{
cout<<a<<endl;
break;
}
}
if(a==66) cout<<"no"<<endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
附上原题:
Ignatius's puzzle
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
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