POJ 3103 Astronomy
来源:互联网 发布:淘宝外卖怎么加入配送 编辑:程序博客网 时间:2024/06/05 16:31
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
题目大意
已知每个星体的运行周期,问最少经过多长时间所有的星体能够处于同一条直径上。
解题思路
这道题好像可以是一道单纯的数学题~
1、以第一个星体为参照点,假设其周期为T0,其余星体的周期为Ti,则两个星体的角速度差值为
2、求一系列分数的lcm=分子的lcm/分母的gcd。
3、涉及到大数乘法的处理,因为这里星体个数范围为1000,星体周期为10000,所以开辟1000位数组对数据压4位来存储结果。
代码实现
#include <iostream>#include<cstdio>#include<stdlib.h>#include<cstring>#include<cmath>using namespace std;#define N 1000#define M 10000int r[N];int a,b,c,d;int countt[M];int T0,T1;//求gcdint gcd(int a,int b){ if(!b) return a; else return gcd(b,a%b);}//素因子分解void getfac(int x){ int num; for(int j=2; x>1; j++) { if(x%j==0) { num=0; while(x%j==0) { num++; x/=j; } if(num>countt[j]) countt[j]=num; //countt[]记录每个因子的个数 } }}void getup(){ int temp; for(int i=0; i<M; i++) //M代表因子的范围,因为1<=ti<=10000,则i最大值为9997 { for(int j=0; j<countt[i]; j++) //j遍历因子个数 { temp=0; for(int k=0; k<N; k++) //N代表位数的极限,示例:9997 9995 9993 { r[k]=r[k]*i+temp; temp=r[k]/10000; r[k]%=10000; } } }}int main(){ int T; while(~scanf("%d",&T)) { memset(countt,0,sizeof(countt)); d=0; scanf("%d",&T0); T--; while(T--) { scanf("%d",&T1); if(T1!=T0) { a=T0*T1; b=2*abs(T0-T1); c=gcd(a,b); a=a/c; b=b/c; d=gcd(b,d); getfac(a); } } memset(r,0,sizeof(r)); r[0]=1; getup(); int i=999; while(i&&r[i]==0) i--; printf("%d",r[i]); for(i--; i>=0; i--) printf("%04d",r[i]); printf(" %d\n",d); } return 0;}
- POJ 3103 Astronomy
- Astronomy POJ
- poj 3101 astronomy
- POJ 3101 Astronomy
- POJ 3101 Astronomy
- POJ 3101 Astronomy
- poj 3101 Astronomy
- POJ 3101 Astronomy
- POJ 3101 Astronomy .
- POJ 3101 Astronomy 可能会
- POJ 3101 Astronomy 笔记
- POJ 3101 Astronomy (大数+LCM)
- POJ 3101 Astronomy (数学)
- poj 3101 Astronomy(分数的最小公倍数)
- poj 3101 Astronomy (大数java)
- 【POJ 3101】Astronomy(GCD+LCM+公式)
- POJ - 3101 Astronomy(有理数的公倍数)
- POj-3101-Astronomy(分数GCD+BigInteger)
- 屏蔽android ota升级包时间戳比较
- CSDN日报20170424 ——《技术方向的选择》
- jenkins复制项目插件、Fir.im、SCM、multibranc链接推荐
- Mysql的基本操作
- Navicat设置字段类型
- POJ 3103 Astronomy
- SQLite--函数介绍
- 整理的前端面试题3
- 编写你自己的单点登录(SSO)服务
- 哈哈
- 一条语句交换两个元素值
- Density Peak改进(overlapping)
- SRM548 Div1Medium KingdomAndDice
- 过滤器和监听器