Divide numbers (divisible large numbers)

Digit Divide

Title description
Theorem: Remove the ones digit of a positive integer with at least two digits, and then subtract 5 times the single digit from the remaining number. If and only if the difference is a multiple of 17, the original number is also a multiple of 17.
For example, 34 is a multiple of 17, because 3-20=-17 is a multiple of 17; 201 is not a multiple of 17, because 20-5=15 is not a multiple of 17. Enter a positive integer n, and your task is to determine whether it is a multiple of 17.

Input The
input file contains up to 10 sets of test data, each of which occupies one line, and only contains a positive integer n (1<=n<=10^100), which represents the positive integer to be judged. n=0 means the end of input, and your program should not process this line.

Output
For each group of test data, output one line to indicate whether the corresponding n is a multiple of 17. 1 means yes, 0 means no.

Sample input
34
201
2098765413
1717171717171717171717171717171717171717171717171718
0

Sample output
1
0
1
0

#include<stdio.h>
#include<string.h>
int main()
{
    
    
    char s[1010];
    int a[1010],b[1010],i,l,x,y;
    while(scanf("%s",s))
    {
    
    
        if(s[0]=='0')
        break;
        x=y=0;
        l=strlen(s);
        for(i=0;i<l;i++)//字符串转换为数组,不转也可以算.
        {
    
    
            a[i]=s[i]-'0';
        }
        for(i=0;i<l;i++)
        {
    
    
            x=x*10+a[i];//x每次*10+a[i]表示从最高位依次变大10倍
            x=x%17;//每次都对17求余运算,不然会溢出,数太大了.
        }
        if(x==0)
        printf("1\n");
        else
        printf("0\n");
    }
}

Guess you like

Origin blog.csdn.net/m0_46381590/article/details/111416578