Ignatius ' s puzzle
Problem Descriptionignatius is poor at Math,he falls across a puzzle problem,so he have 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 Nonegat Ive integer a,make The arbitrary integer x, 65|f (x) if
No exists that a,then print "no".
Inputthe input contains several test cases. Each test case consists of a nonegative an integer k, more details in the Sample Input.
Outputthe 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
Test instructions: F (x) =5*x^13+13*x^5+k*a*x, find the smallest a, so that for a given k, any x below the F (x) can be divisible by 65.
Idea: play the table to find the law.
You will find that (5*x^13+13*x^5)%65 every 65 x into a cycle. To make the result (k*a*x)%65, it also has to be every 65 loops, and a value is between 0-64, so there is the following code----
Code:
/************************************************* author:ac_sorry* file:* Create date:* motto:one Heart one life* CSDN : http://blog.csdn.net/code_or_code*************************************************/#include <iostream># include<cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <cstdlib > #include <vector> #include <string> #include <map> #include <utility> #include <queue > #include <stack> #define INF 0x3f3f3f3f#define MOD 1000000007#define seed_ 131#define eps 1e-8#define mem (A, B) memset (a,b,sizeof a) #define W (i) t[i].w#define ls (i) t[i].ls#define rs (i) T[i].rsusing namespace std;typedef long long LL; const int N=100010;int a[100];int Main () {//int t;scanf ("%d", &t); int ac=0; for (int x=1;x<=65;x++) a[x]= (5*x%65*x*x%65*x*x%65*x*x%65*x*x%65*x*x%65*x*x%65+13*x%65*x*x%65*x*x%65)%65; int k; while (scanf ("%d", &k) ==1) {int ok,ans; for (int aa=0;aa<65;aa++) {ok=1; for (int i=1;i<=65;i++) {if ((a[i]+k*i%65*aa%65)%65!=0) {OK = 0; Break }} if (ok) {ans=aa; Break }} if (OK) printf ("%d\n", ans); else printf ("no\n"); } return 0;}
hdu_1098 Ignatius ' s puzzle[law problem]