Issues 1074: Digital divisible

Title Description

Theorem: The at least two of a single-digit positive integer removed, and then from the remaining number of times by subtracting the 5-digit number. If and only if the difference is a multiple of 17, the original number is a multiple of 17.

For example, a multiple of 17, 34, -17 = 3-20 as a multiple of 17; 17 is not a multiple of 201, since 15 is not a multiple of 20-5 = 17. Enter a positive integer n, your task is to determine whether it is a multiple of 17.

Entry

Input file containing up to 10 test cases, each data per line, comprising only a positive integer n (1 <= n <= 10 ^ 100), represents a positive integer to be determined. n = 0 indicates the end of input, your program should not deal with this line.

Export

For each test, output a line indicating whether the corresponding n is a multiple of 17. 1 is yes, 0 for no.

Sample input
34
201
2098765413
1717171717171717171717171717171717171717171717171718
0
Sample Output
1
0
1
0

import java.math.BigInteger;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main{
public static void main(String args[]){
  Scanner in = new Scanner(System.in);
  int ge;
  BigInteger zheng;
  int index=0;
  int a[] = new int[10];
  while(true){
    String s = in.next();
    if(s.equals("0"))
      break;
    BigInteger bg = new BigInteger(s);
    ge=5*Integer.parseInt(s.substring(s.length()-1));
    zheng = bg.divide(BigInteger.valueOf(10));

    if((zheng.subtract(BigInteger.valueOf(ge))).mod(BigInteger.valueOf(17))==BigInteger.valueOf(0)){
      a[index]=1;
}
  else
    a[index]=2;
    index++;
}
  for(int i=0;i<a.length;i++){
    if(a[i]==1){
      System.out.println(a[i]);
}
  else if(a[i]==2){
    System.out.println(a[i]-2);
}
}
}
}

Guess you like

Origin www.cnblogs.com/xuesujun/p/11370156.html