TOJ 3486 Divisibility

Description

On the planet Zoop, numbers are represented in base 62, using the digits
0, 1, . . . , 9, A, B, . . . , Z, a, b, . . . , z
where
A (base 62) = 10 (base 10)
B (base 62) = 11 (base 10)
...
z (base 62) = 61 (base 10).
Given the digit representation of a number x in base 62, your goal is to determine if x is divisible by 61.

Input

The input test file will contain multiple cases. Each test case will be given by a single string containing only the digits ‘0’ through ‘9’, the uppercase letters ‘A’ through ‘Z’, and the lowercase letters ’a’ through ’z’. All strings will have a length of between 1 and 10000 characters, inclusive. The end-of-input is denoted by a single line containing the word “end”, which should not be processed. For example:

1v3
2P6
IsThisDivisible
end

Output

For each test case, print “yes” if the number is divisible by 61, and “no” otherwise. For example:
yes
no
no
In the first example, 1v3 = 1 × 622 + 57 × 62 + 3 = 7381, which is divisible by 61.
In the second example, 2P6 = 2 × 622 + 25 × 62 + 6 = 9244, which is not divisible by 61.

Sample Input

1v3
2P6
IsThisDivisible
end

Sample Output

yes
no
no

Source

SLPC 2007

 

62进制的数是否能被61整除。

输入的数达10000位,但是可以一边运算一边mod。

 

#include 
#include <string.h>

int convertToInt(char a){
    if('0'<=a && a<='9')return a-'0';
    if('A'<=a && a<='Z')return a-'A'+10;
    if('a'<=a && a<='z')return a-'a'+36;
}

int main()
{
    char ch[10001];
    while( scanf("%s",ch), strcmp("end",ch)!=0 ){
        int mo=0;
        int temp=1;
        for(int i=0; ch[i]!='\0'; i++,temp*=62){
            mo+=convertToInt(ch[i])*temp;
            mo%=61;
            temp%=61;
        }
        if(mo==0){
            puts("yes");
        }else{
            puts("no");
        }
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/chenjianxiang/p/3554763.html

你可能感兴趣的:(TOJ 3486 Divisibility)