LightOJ1024(LCM+高精度乘法)

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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值