lightoj 1024
来源:互联网 发布:性快感 知乎 编辑:程序博客网 时间:2024/06/02 02:34
In a strange planet there are n races. They are completely different as well as their food habits. Each race has a food-eating period. That means the ith race eats after every xi de-sec (de-sec is the unit they use for counting time and it is used for both singular and plural). And at that particular de-sec they pass the whole day eating.
The planet declared the de-sec as 'Eid' in which all the races eat together.
Now given the eating period for every race you have to find the number of de-sec between two consecutive Eids.
Input
Input starts with an integer T (≤ 225), denoting the number of test cases.
Each case of input will contain an integer n (2 ≤ n ≤ 1000) in a single line. The next line will contain n integers separated by spaces. The ith integer of this line will denote the eating period for the ith race. These integers will be between 1 and 10000.
Output
For each case of input you should print a line containing the case number and the number of de-sec between two consecutive Eids. Check the sample input and output for more details. The result can be big. So, use big integer calculations.
Sample Input
Output for Sample Input
2
3
2 20 10
4
5 6 30 60
Case 1: 20
Case 2: 60
#include<bits/stdc++.h>#define N 10000+10#define MOD 10000using namespace std;typedef long long ll;int a[N],ans[N];int fun(int x,int n){ ll rev=1; for(int i=1;i<=n;i++) rev*=x; return rev;}void multi(int n){ for(int i=0;i<1000;i++) ans[i]*=n; for(int i=0;i<1000;i++) { ans[i+1]+=ans[i]/MOD; ans[i]=ans[i]%MOD; }}void print(){ int i=1000; while(i>=0&&ans[i]==0) i--; printf("%d",ans[i]); i--; while(i>=0) printf("%04d",ans[i--]); printf("\n");}int main(){ int t,n,num; cin>>t; for(int cas=1; cas<=t; cas++) { memset(a,0,sizeof(a)); memset(ans,0,sizeof(ans)); scanf("%d",&n); for(int i=0; i<n; i++) { scanf("%d",&num); int j; for(j=2; j*j<=num; j++) { int cnt=0; while(num%j==0) { num=num/j; cnt++; } a[j]=max(a[j],cnt); } if(num>1) a[num]=max(a[num],1); } ans[0]=1; for(int i=1; i<N; i++) { if(!a[i]) continue; int flag=fun(i,a[i]); multi(flag); } printf("Case %d: ",cas); print(); } return 0;}
- lightoj 1024
- lightoj 1024
- LightOJ 1024 Eid
- lightoj 1024 Eid
- LightOJ 1024 Eid
- LightOJ 1024 Eid
- LightOj-1024-Eid
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- [LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- LightOJ
- ArrayUtils常用的几个函数
- struts学习入门
- Linux网络命令(5):netstat命令
- Jmeter使用插件监控远端服务器性能数据
- java.lang.IllegalArgumentException: No converter found for return value of type
- lightoj 1024
- Mybatis 逆向工程生成代码
- 剑指offer中树的总结(基于树的深度)
- JAVA 动态代理
- Y2 三级管电路工作原理及详解
- 心理学助力市场营销策略
- git 删除错误提交的commit
- mvn命令整理1.0
- 我教宝宝学AI(六)听吴恩达老师课程