OpenJ_POJ C16D Extracurricular Sports 打表找规律
2016-07-19 18:13
323 查看
Extracurricular Sports
题目连接:
http://acm.hust.edu.cn/vjudge/contest/122701#problem/DDescription
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
13
Sample Output
1020
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 [j] ); } } } }
相关文章推荐
- Linux系统分区原理
- 微服务架构的分布式事务问题
- Linux入门指令
- Java安全框架 Apache Shiro学习-1-ini 配置
- 资料网站收集
- OpenJ_POJ C16B Robot Game 打表找规律
- 访问opencv的Mat中的图像数据
- web前端-二级分类菜单(类似购物网站)
- 在Centos中yum安装和卸载软件的使用方法
- display: none;、visibility: hidden、opacity=0区别总结
- DPM中global.m从linux移植到windows的改动in 4.01.1(没写源代码,可自行下载)
- linux 下查看机器是cpu是几核的
- docker registry api
- linux下 open() write() read() close函数
- 网站的PV UV IP---网站常见软件性能
- linux grep 入门
- Linux Top命令
- Linux环境安装OpenCV
- Ubuntu14.04安装Linux源码
- OpenCV初级教程