【POJ3101】Astronomy——分子的最小公倍数
来源:互联网 发布:形容闪亮的网络词语 编辑:程序博客网 时间:2024/04/28 09:57
Astronomy
Time Limit: 2000MS Memory Limit: 65536K
Description
There are n planets in the planetary system of star X. They orbit star X in circular orbits located in the same plane. Their tangent velocities are constant. Directions of orbiting of all planets are the same.
Sometimes the event happens in this planetary system which is called planet parade. It is the moment when all planets and star X are located on the same straight line.
Your task is to find the length of the time interval between two consecutive planet parades.
Input
The first line of the input file contains n — the number of planets (2 ≤ n ≤ 1 000).
Second line contains n integer numbers ti — the orbiting periods of planets (1 ≤ ti ≤ 10 000). Not all of ti are the same.
Output
Output the answer as a common irreducible fraction, separate numerator and denominator by a space.
Sample Input
3
6 2 3
Sample Output
3 1
Hint
Source
Northeastern Europe 2005, Northern Subregion
题意:已知每一个行星的周期,求他们共线的最短的时间。
分析:每一个行星的角速度为vi=2πTi,选择行星0为参考点,则相对于行星0的角速度为v′i=2πTi−T0TiTo,则转动半圈的时间为T′i=πv′i=TiT02(Ti−T0)问题就转化为求T′1,T′2,T′3⋯,T′n−1的最小公倍数最小公倍数:对于整数的最小公倍数为LCM(a,b)=a×bGCD(a,b),那么对于分数呢?结论:LCM(ab,cd)=LCM(a,c)GCD(b,d)证明:假设mn是ab,cd的最小公倍数,那么mn×ba=N,mn×dc=N′显然m是a,c的倍数,n是b,d的约数,由于是最小公倍数,那么自然是m尽量的小,n尽量的大。所以m=LCM(a,c),n=GCD(b,d)。由于数据的结果比较的大,所以用高精度算法或者是Java。
import java.math.*;import java.util.*;public class Main { public static void main(String[ ] args) { Scanner cin = new Scanner(System.in); int n ,cnt; int [ ] t =new int[1100]; int [ ]s = new int [1100]; BigInteger a,b,g,mo = null,de = null; while(cin.hasNext()) { cnt = 1; n = cin.nextInt(); for(int i = 0;i<n;i++) t[i] = cin.nextInt(); Arrays.sort(t,0,n); s[0] =t[0]; for(int i = 1;i<n;i++) { if(t[i]!=t[i-1]) { s[cnt++] = t[i]; } } for(int i = 1;i<cnt;i++) { a = BigInteger.valueOf(s[i]*s[0]); b = BigInteger.valueOf((s[i]-s[0])*2); g = a.gcd(b); if(i == 1) { mo = a.divide(g); de = b.divide(g); } else { a = a.divide(g); b = b.divide(g); mo = mo.multiply(a).divide(mo.gcd(a)); de = de.gcd(b); } } System.out.println(mo+" "+de); } cin.close(); }}
- 【POJ3101】Astronomy——分子的最小公倍数
- poj3101--Astronomy(分数的最小公倍数)
- poj3101——Astronomy(大数数学&gcd)
- [POJ3101]Astronomy
- poj 3101 Astronomy(分数的最小公倍数)
- POJ3101 Astronomy【素因子分解】【大数乘法】
- (Relax 数论 1.17)POJ 3101 Astronomy(分数的最小公倍数)
- (转)POJ3101 Astronomy【素因子分解】【大数乘法】
- poj3101
- Astronomy poj 3101 数论 分数的最小公倍数 Cherish the memory of my broken heart
- POJ 3101 Astronomy 轨道相遇问题,求n个分数的最小公倍数
- poj_3101 Astronomy(大整数+分数最小公倍数)
- 一个SDL的实验——模拟分子的运动
- 狂热分子——码头工人的哲学沉思录
- POJ 3101 Astronomy 解题报告(大数乘法+分数最小公倍数)
- POJ - 3101 Astronomy(有理数的公倍数)
- 最小公倍数——核桃的数量
- 解题笔记(28)——寻找捣乱分子对
- HTTP深入浅出 http请求
- POJ2479&&POJ2593 Maximum sum&&Max Sequence(最大连续和)
- ubuntu使用apt get install 安装nginx和php-fpm
- 存储过程(三、事务的处理和回滚)
- canvas粗略绘制广东海洋大学图书馆,钟海楼...
- 【POJ3101】Astronomy——分子的最小公倍数
- 存储过程(四)查询,使用的是jdbc
- HDU训练记录1:KMP
- 引入ping++的server SDK,thinkphp报错:unexpected 符号“,”
- linux下使用gitHub环境搭建
- 存储过程五(分页)
- 博弈游戏
- CSS3----新增特性及其在主流浏览器中的兼容性
- vs解决无符号类型,安全开发生命周期(SDL)检查