OpenJ_POJ C16D Extracurricular Sports 打表找规律
Extracurricular Sports
题目连接:
http://acm.hust.edu.cn/vjudge/contest/122701#problem/D
Description
As we all know, to pass PE exams, students need to do extracurricular sports, especially jogging. As the result, the Jogging Association in the university is very popular.
There are N students in the Jogging Association. Some run faster while the others run slower. The time it takes for a student to run exactly one lap is called his/her ''lap time'', which is always a positive integer. The lap times of students are distinct from each other. However, running too slow is not allowed for students of the Jogging Association, so each lap time is at most 100 digits.
One day, they make an appointment to jog together. They begin at the same time as well as the same starting point, jog along the circular runway at their own steady speed round and round, not stop until the first time when all of them meet again at the starting point. When they stop, they accidently find that the time they have spent is precisely equal to the time they need if everyone runs a lap one by one, as a relay race.
Now we are curious about the lap times of all the students. Can you guess out any possible solution?
Input
The first line contains an integer T (1 ≤ T ≤ 30), indicating the number of test cases.
For each test case:
A line contains an integer N (2 ≤ N ≤ 200), indicating the number of students.
Output
For each test case:
If the solution does not exist, output -1 on a single line;
Otherwise, output one solution with n different integers t1,t2,...,tn, one per line, where ti (1 ≤ ti < 10^100) indicates the lap time of the i-th student. If there are several solutions, output any one.
Sample Input
1
3
Sample Output
10
20
30
Hint
题意
让你构造出n个不同的数,使得这n个数的lcm等于这n个数的和
题解:
还是打表找规律
发现就是 1 2 3 -> 1 2 6 9 -> 1 2 6 18 27 -> 1 2 6 18 54 81 .....这样就行了
代码
import java.io.*;
import java.math.*;
import java.util.*;
public class Main
{
static BigInteger ans[][] = new BigInteger[250][250];
public static void main(String argv[]) throws Exception
{
Scanner cin = new Scanner(System.in);
ans[3][1] = BigInteger.valueOf(1) ;
ans[3][2] = BigInteger.valueOf(2) ;
ans[3][3] = BigInteger.valueOf( 3 );
for(int i = 3 ; i <= 200 ; ++ i){
for(int j = 1 ; j <= i - 1 ; ++ j) ans[i + 1][j] = ans[i][j];
ans[i + 1][i] = ans[i][i].multiply(BigInteger.valueOf(2));
BigInteger sum = BigInteger.ZERO;
for(int j = 1 ; j <= i ; ++ j) sum = sum.add( ans[i + 1][j] );
ans[i + 1][i + 1] = sum;
}
int T = cin.nextInt();
for(int cas = 1 ; cas <= T ; ++ cas ){
int N = cin.nextInt();
if( N == 2 ) System.out.println( -1 );
else{
for(int j = 1 ; j <= N ; ++ j) System.out.println( ans[N][j] );
}
}
}
}