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
2
3
2 20 10
4
5 6 30 60
Sample Output
Case 1: 20
Case 2: 60
题解:这道题没什么可说的就只是有一个高精度的乘法而已
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define _INIT ios::sync_with_stdio(false);cin.tie(nullptr);cout.precision(10);cout<<fixed
#define clr(a,b) memset(a,b,sizeof(a))
#define MAX_N 100010+2
typedef long long ll;
const ll maxn=1e3+5;
int cnt[MAX_N],ans[MAX_N],len;
inline bool read(ll &num)
{
char in;bool IsN=false;
in=getchar();
if(in==EOF) return false;
while(in!='-'&&(in<'0'||in>'9')) in=getchar();
if(in=='-'){ IsN=true;num=0;}
else num=in-'0';
while(in=getchar(),in>='0'&&in<='9'){
num*=10,num+=in-'0';
}
if(IsN) num=-num;
return true;
}
ll mult(int a,int b)
{
if(a<b)
swap(a,b);
ll ans=0;
while(b)
{
if(b&1)ans+=a;
b>>=1;
a<<=1;
}
return ans;
}
ll pown(int a,int b)
{
ll ans=1;
while(b)
{
if(b&1){ans=mult(a,ans);}
a=mult(a,a);
b>>=1;
}
return ans;
}
void prime(int x)
{
int ans=0;
for(int i=2; i*i<=x; i++)
{
if(x%i==0)
{
int num=0;
while(x%i==0)
{
x/=i;
num++;
}
cnt[i]=max(cnt[i],num);
}
}
if(x!=1)
{
cnt[x]=max(cnt[x],1);
}
return ;
}
void multiply(int x)
{
for(int i=0; i<len; i++) ans[i]*=x;
for(int i=0;i<len;i++)
{
ans[i+1]+=ans[i]/10;
ans[i]%=10;
}
ll tmp=ans[len];
while(tmp)
{
ans[len++]=tmp%10;
tmp/=10;
}
return ;
}
int main()
{
//freopen("data.out","w+",stdout);
ll t1,t2;
char tch;
int t;
scanf("%d",&t);
for(int ti=1; ti<=t; ti++)
{
clr(cnt,0);
clr(ans,0);
int n;
scanf("%d",&n);
for(int i=1; i<=n; i++)
{
int tm;
scanf("%d",&tm);
prime(tm);
}
ans[0]=len=1;
printf("Case %d: ",ti);
for(int i=2;i<=10000;i++){if(cnt[i]) {multiply(pow(i,cnt[i]));}}
for(int i=len-1;i>=0;i--){printf("%d",ans[i]);}
printf("\n");
}
return 0;
}