2013
12-12

# 九度-1036-Old Bill[解题代码]

Among grandfather’s papers a bill was found.
72 turkeys $_679_ The first and the last digits of the number that obviously represented the total price of those turkeys are replaced here by blanks (denoted _), for they are faded and are illegible. What are the two faded digits and what was the price of one turkey? We want to write a program that solves a general version of the above problem. N turkeys$_XYZ_
The total number of turkeys, N, is between 1 and 99, including both. The total price originally consisted of five digits, but we can see only the three digits in the middle. We assume that the first digit is nonzero, that the price of one turkeys is an integer number of dollars, and that all the
turkeys cost the same price.
Given N, X, Y, and Z, write a program that guesses the two faded digits and the original price. In case that there is more than one candidate for the original price, the output should be the most expensive one. That is, the program is to report the two faded digits and the maximum price per turkey for the turkeys.

The first line of the input file contains an integer N (0<N<100), which represents the number of turkeys. In the following line, there are the three decimal digits X, Y, and Z., separated by a space, of the original price \$_XYZ_.

For each case, output the two faded digits and the maximum price per turkey for the turkeys.

72
6 7 9
5
2 3 7
78
0 0 5

3 2 511
9 5 18475
0

java 代码如下：
import java.util.Scanner;

public class Main{

static int num,x,y,z;
static int a = 0,b = 0,c = 0;
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while(scan.hasNextInt()){
num = scan.nextInt();
x = scan.nextInt();
y = scan.nextInt();
z = scan.nextInt();
int mid = x*1000 + y*100 + z*10;
a = 0;
b=0;c=0;
for(int i=0; i<10; i++){
for(int j=0; j<10; j++){
int temp = i*10000 + mid + j;
if(temp % num == 0){
a = i;
b = j;
c = temp / num;
}
}
}
if(a==0 && b==0)
System.out.println(c);
else
System.out.println(a + " " + b + " " + c);
}
}

}
/**************************************************************
Problem: 1036
User: coder
Language: Java
Result: Accepted
Time:80 ms
Memory:15504 kb
****************************************************************/

1. 为什么for循环找到的i一定是素数叻，而且约数定理说的是n=p1^a1*p2^a2*p3^a3*…*pk^ak，而你每次取余都用的是原来的m，也就是n