Ignatius's puzzle
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9049 Accepted Submission(s): 6288
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(x)=5*x^13+13*x^5+k*a*x,输入一个k,让你求使得f(x)%65==0的a的最小值是多少。完全的数学题,刚开始也是一头雾水。。。仔细想想用数学归纳法,因为对于任意x都要成立,所以f(x+1)和f(x)成立,对于f(x+1),展开得到f(x+1)=5*(C(13,0)*x^13+C(13,1)*x^12+...C(13,13)*x^0)+13*(C(5,0)*x^5+C(5,1)*x^4+...+C(5,5)*x^0)+k*a*(x+1)f(x+1)=5*x^13+13*x^5+k*a*x+5*(C(13,1)*x^12+...C(13,13)*x^0)+13*(C(5,1)*x^4+...+C(5,5)*x^0)+k*a而f(x)=5*x^13+13*x^5+k*a*x即f(x+1)=f(x)+5*(C(13,1)*x^12+...C(13,13)*x^0)+13*(C(5,1)*x^4+...+C(5,5)*x^0)+k*af(x+1)=f(x)+5*(C(13,1)*x^12+...C(13,12)*x^1)+13*(C(5,1)*x^4+...+C(5,4)*x^1)+k*a+18可以发现f(x+1)中,f(x)是能被65整除的,5*(C(13,1)*x^12+...C(13,12)*x^1)+13*(C(5,1)*x^4+...+C(5,4)*x^1)这一长段也是能够被65整除的,这是因为其中都含有5*13因子,所以问题就化成了k*a+18能否被65整除了。求其最小值,考虑(k*a+18)%65=(k*a%65+18%65)%65,所以只需将a从1到65遍历,即可判断能否被65整除,同时找出最小值。#include<cstdio> #include<cstdlib> #include<iostream> #include<stack> #include<queue> #include<algorithm> #include<string> #include<cstring> #include<cmath> #include<vector> #include<map> #include<set> #define eps 1e-8 #define zero(x) (((x>0?(x):-(x))-eps) #define mem(a,b) memset(a,b,sizeof(a)) #define memmax(a) memset(a,0x3f,sizeof(a)) #define pfn printf("\n") #define ll __int64 #define ull unsigned long long #define sf(a) scanf("%d",&a) #define sf64(a) scanf("%I64d",&a) #define sf264(a,b) scanf("%I64d%I64d",&a,&b) #define sf364(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c) #define sf2(a,b) scanf("%d%d",&a,&b) #define sf3(a,b,c) scanf("%d%d%d",&a,&b,&c) #define sf4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d) #define sff(a) scanf("%f",&a) #define sfs(a) scanf("%s",a) #define sfs2(a,b) scanf("%s%s",a,b) #define sfs3(a,b,c) scanf("%s%s%s",a,b,c) #define sfd(a) scanf("%lf",&a) #define sfd2(a,b) scanf("%lf%lf",&a,&b) #define sfd3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c) #define sfd4(a,b,c,d) scanf("%lf%lf%lf%lf",&a,&b,&c,&d) #define sfc(a) scanf("%c",&a) #define ull unsigned long long #define debug printf("***\n") const double PI = acos(-1.0); const double e = exp(1.0); const int INF = 0x7fffffff;; template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template<class T> inline T Min(T a, T b) { return a < b ? a : b; } template<class T> inline T Max(T a, T b) { return a > b ? a : b; } bool cmpbig(int a, int b){ return a>b; } bool cmpsmall(int a, int b){ return a<b; } using namespace std; int main() { // freopen("data.in","r",stdin); int k; while(~sf(k)) { int cnt,i; for(i=1;i<=65;i++) { cnt=18+i*k; if(cnt%65==0) break; } if(i==66) printf("no\n"); else printf("%d\n",i); } return 0; }