HDU 1098 Ignatius's puzzle (number theory-Others)

Source: Internet
Author: User
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;}



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.