Large number of 51NOD 1116 K-Binary (string modulo + enumeration)

Source: Internet
Author: User

Transmission Door
Large number of 1116 K-Input system
Base time limit: 1 seconds space limit: 131072 KB score: 20 Difficulty: 3-Level algorithm topic collection concern
There is a string s, record a large number, but do not know how much this large number of binary, only know that the number in the K-system is a multiple of K-1. Now it's up to you to find out the smallest of the binary K.
For example, the given number is A1A, there is a is at least 11 binary, and then found that A1A in 22 is equal to 4872,4872 mod 21 = 0, and 22 is the smallest, so the output k = 22 (large number of the representation of a corresponding to 10,z 35).
Input
Enter the string s corresponding to the large number. The length of S is less than 10^5.
Output
The output corresponding to the binary k, if the corresponding solution is not found in the range of 2-36, then output no solution.
Input example
A1a
Output example
22

Problem Solving Ideas:
In fact, we are the enumeration from the largest number of +1 to start the enumeration, until the end of 36, and then the basic operation is to take the string modulo, a string to modulo, we only need to multiply its number of bits each time, and then a summation of the modulo is OK, because the modulo operation can be calculated separately. (In fact, I think the problem is mainly to investigate the string modulus)

On the code:

#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>using namespace STD;Const intMAXN =1e5+5;CharS[MAXN];intMain () { while(Cin>>s) {intLen =strlen(s), Max =-1; for(intI=0; i<len; i++) {if(s[i]>=' A '&& s[i]<=' Z ') max = max (max, (s[i]-' A '+Ten));Else{max = max (max, (s[i]-' 0 ')); }        }///cout<<max<<endl;        if(Max = =0)///(in this case, in fact, no special sentence can be too){puts("No Solution");Continue; } for(inti=max+1; i<= $; i++) {intsum =0; for(intj=0; j<len; J + +) {if(s[j]>=' A '&& s[j]<=' Z ') {sum = sum*i+ (s[j]-' A '+Ten); Sum%= (i-1); }Else{sum = sum*i+ (s[j]-' 0 '); Sum%= (i-1); }            }if(Sum = =0)            {cout<<i<<endl;GotoENDW; }        }puts("No Solution");    ENDW:; }return 0;}

Large number of 51NOD 1116 K-Binary (string modulo + enumeration)

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.