1008: number divisible time limit: 1 sec memory limit: 128 MB
Submission: 6 solution: 4
[Submit] [Status] [discussion version] Description
Theorem: Remove a single-digit number with at least two positive integers, And then subtract 5 times of the single-digit number from the remaining number. When the only 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. Your task is to determine whether it is a multiple of 17.
Input
The input file contains up to 10 groups of test data, each of which occupies one row and contains only one positive integer N (1 <= n <= 10100), indicating the positive integer to be judged. N = 0 indicates that the input is over. Your program should not process this line.
Output
For each group of test data, the output line indicates whether the corresponding N is a multiple of 17. 1 indicates yes, 0 indicates no.
Sample Input
34201209876541317171717171717171717171717171717171717171717171717180
Sample output
1010
Prompt
Simple big data problems:
At first, we thought we could just get through the water. This code is directly wa;
#include <cstdio>#include <cstring>int main(){ long long n; long long sum; while(scanf("%I64d",&n)&&n!=0) { sum=n/10-(n%10*5); if(sum%17==0) printf("1\n"); else printf("0\n"); } return 0;}
Later, I used Java for big data processing;
Import Java. math. biginteger; import Java. util. extends; public class nyist664 {public static void main (string [] ARGs) {extends scanf = new evaluate (system. in); While (scanf. hasnext () {biginteger sum = scanf. nextbiginteger (); If (sum. equals (biginteger. zero) break; biginteger n = biginteger. valueof (5); // convert int type to biginteger type biginteger M = biginteger. valueof (17); sum = sum. divide (biginteger. ten ). subtract (sum. moD (biginteger. ten ). multiply (n); // according to the question, remove the single digit, minus the single digit multiplied by the value of 5 sum = sum. moD (m); // modulo 17if (sum. equals (biginteger. zero) {system. out. println (1);} else system. out. println (0 );}}}
This is based on the meaning of the question;
Or you can simply follow the Java Big Data Model 17;
Import Java. math. biginteger; import Java. util. extends; public class main {public static void main (string [] ARGs) {extends scanf = new evaluate (system. in); While (scanf. hasnext () {biginteger sum = scanf. nextbiginteger (); If (sum. equals (biginteger. zero) break; biginteger n = biginteger. valueof (17); // sum = sum. divide (biginteger. ten)-(sum. moD (biginteger. ten ). multiply (n); // sum = sum is entered incorrectly here. moD (n); If (sum. equals (biginteger. zero) {system. out. println (1);} else system. out. println (0 );}}}
Later, I saw code that someone else had used C ++ and the integer that I used directly. I feel that the integer type should not be enough, but it is too much;
#include<stdio.h>int main(){int i,sum;char str[105];while(scanf("%s",str)&&str[0]!='0'){sum=0;for(i=0;str[i]!='\0';i++){sum=sum*10+str[i]-'0';sum=sum%17;}printf("%s\n",sum?"0":"1");}return 0;}
This code is also concise and highly efficient;