Ignatius's puzzle
Problem descriptionignatius is poor at math, he falls into ss 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 ".
Inputthe input contains several test cases. Each test case consists of a nonegative integer k, more details in the sample input.
Outputthe output contains a string "no", if you can't find a, or you shoshould output a line contains the. More details in the sample output.
Sample Input
111009999
Sample output
22no43
Authoreddy
Recommendwe have carefully selected several similar problems for you: 1071 1014 1052 1097 1082
Question:
Given a K, find the smallest a so that f (x) = 5 * x ^ 13 + 13 * x ^ 5 + K * a * X, f (x) % 65 is always equal to 0
Solution:
Because f (x + 1) = 5 * (x + 1) ^ 13 + 13 * (x + 1) ^ 5 + K * a * X, so f (x + 1) = f (x) + 5*(13 1) x ^ 12 ........... + (13 13) x ^ 0) + 13*(5 1) x ^ 4 + ........... + (5 5) x ^ 0) + K * A except for 5*(13 13) x ^ 0, 13*(5 5) x ^ 0, and K *, all other items can be divisible by 65. then, you only need to find that 18 + K * A can be fully divided by 65.
18 + K * A = 65 * B
A sufficient and required condition for the equation AX + by = C to have a solution is: C % gcd (a, B) = 0
Solution Code:"
#include <iostream>#include <cstdio>using namespace std;int gcd(int a,int b){ return b>0?gcd(b,a%b):a;}int main(){ int k; while(scanf("%d",&k)!=EOF){ if(18%gcd(k,65)==0){ for(int a=0;;a++){ if( (18+k*a)%65==0 ){ printf("%d\n",a); break; } } } else printf("no\n"); } return 0;}