题目链接: http://lightoj.com/volume_showproblem.php?problem=1024

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 (≤ ), denoting the number of test cases. Each case of input will contain an integer n ( ≤ n ≤ ) 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 and . 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
Case :
Case :

题目大意:给出n个数  求n个数的最小公倍数;

思路:求最小公倍数可以用最大公约数来求,但是由于n的大小与每个数的大小,所以最后说求得最小公倍数可能是个大数,所以需要用到大数相乘;

利用每个数的因子求最小公倍数。例如:

5 的因子 5;

6的因子 2 3;

30的因子 2 3 5;

60的因子 2 2 3 5;

保存出现的每个因子最大个数  2个2 1个3 1个5 相乘就得到最小公倍数 60;

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include <map>
#include <string>
#include <vector>
#include<iostream>
using namespace std;
#define N 100006
#define INF 0x3f3f3f3f
#define LL long long
#define mod 1000000007
int prim[N];
int arr[N],ans[N];
int k =;
void Init()///先打个素数表
{
memset(arr,,sizeof(arr));
for(int i=;i<=;i++)
{
if(!arr[i])
{
prim[k++] = i;
for(int j=i;j<=;j+=i)
arr[j] = ;
}
}
}
void mul(int n)///大数相乘
{
for(int i=;i<;i++)
ans [i] = ans[i]*n;
for(int i=;i<;i++)
{
ans[i+] +=ans[i]/;
ans[i] = ans[i]%;
}
}
void prin()///大数输出
{
int i = ;
while(i>= && !ans[i]) i--;
printf("%d",ans[i--]);
while(i>=)
printf("%04d",ans[i--]);
printf("\n");
}
int main()
{
int T;
int con=;
Init();
scanf("%d",&T);
while(T--)
{
int n,num;
scanf("%d",&n);
memset(arr,,sizeof(arr));
for(int i=;i<n;i++)
{
scanf("%d",&num);
for(int j=;j<k&&prim[j]*prim[j]<=num;j++)
{
int s = ;
while(num%prim[j]==)///统计每个数每个因子的个数
{
s++;
num = num/prim[j];
}
arr[prim[j]] = max(s,arr[prim[j]]);///保存当前因子最多的个数
}
if(num>)
arr[num] = max(arr[num],);///这个数为素数
}
memset(ans,,sizeof(ans));
ans[] = ;
for(int i=;i<;i++)
{
if(!arr[i]) continue;
int sum = ;
for(int j=;j<arr[i];j++)
sum = sum*i;
mul(sum);///每个因子相乘
}
printf("Case %d: ",con++);
prin();
}
return ;
}

(light oj 1024) Eid (最小公倍数)的更多相关文章

  1. Light OJ 1114 Easily Readable 字典树

    题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...

  2. Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖

    题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...

  3. Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖

    标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...

  4. Light OJ 1316 A Wedding Party 最短路+状态压缩DP

    题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...

  5. light oj 1007 Mathematically Hard (欧拉函数)

    题目地址:light oj 1007 第一发欧拉函数. 欧拉函数重要性质: 设a为N的质因数.若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N ...

  6. Light OJ 1406 Assassin`s Creed 状态压缩DP+强连通缩点+最小路径覆盖

    题目来源:Light OJ 1406 Assassin`s Creed 题意:有向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路:最少的的人能够走全然图 明显是最小路径覆盖问题 ...

  7. Light OJ 1288 Subsets Forming Perfect Squares 高斯消元求矩阵的秩

    题目来源:Light OJ 1288 Subsets Forming Perfect Squares 题意:给你n个数 选出一些数 他们的乘积是全然平方数 求有多少种方案 思路:每一个数分解因子 每隔 ...

  8. Jan's light oj 01--二分搜索篇

    碰到的一般题型:1.准确值二分查找,或者三分查找(类似二次函数的模型). 2.与计算几何相结合答案精度要求比较高的二分查找,有时与圆有关系时需要用到反三角函数利用 角度解题. 3.不好直接求解的一类计 ...

  9. Light OJ 1272 Maximum Subset Sum 高斯消元 最大XOR值

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/u011686226/article/details/32337735 题目来源:problem=12 ...

随机推荐

  1. ASP.NET Core Middleware 抽丝剥茧

    一. 宏观概念 ASP.NET Core Middleware是在应用程序处理管道pipeline中用于处理请求和操作响应的组件. 每个组件是pipeline 中的一环. 自行决定是否将请求传递给下一 ...

  2. qml demo分析(photosurface-图片涅拉)

    阅读qml示例代码已有一小段时间,也陆续的写了一些自己关于qml示例代码的理解,可能由于自己没有大量的qml开发经验,总感觉复杂的ui交互qml处理起来可能会比较棘手,但事实总是会出人意料,今天我们就 ...

  3. ubuntu16.04无法获取ip地址的解决方案

    当我们无法获取ip地址时可以使用dhcp来动态获取ip地址,安装dhcpcd5和dhcpcd-gtk sudo apt-get install dhcpcd5 sudo apt-get install ...

  4. 深入Go的底层,带你走近一群有追求的人

    目录 缘起 自我介绍的技巧 硬核知识点 什么是plan9汇编 汇编角度看函数调用及返回过程 汇编角度看slice 正确参与Go夜读活动的方式 阅读原文 上周六晚上,我参加了"Go夜读&quo ...

  5. 微信公众号开发C#系列-9、多公众号集中管理

    1.概述 通过前面8篇关于微信开发相关文章的学习,我们已经对微信常用开发有了一个比较深入的了解.前面的文章都是基于某一特定公众号的,在现实业务中同一单位个体运营着不至一个公众号,此时就需要对多个公众号 ...

  6. k8s网络之Flannel网络

    k8s网络主题系列: 一.k8s网络之设计与实现 二.k8s网络之Flannel网络 三.k8s网络之Calico网络 简介 Flannel是CoreOS团队针对Kubernetes设计的一个网络规划 ...

  7. 数据库艰难求生之路(基础:创建数据库表格)part1

     创建表格 1.创建表格之identity create table TableName( id ,), col_1 ), col_2 ) ) 这是一个简单的表格创建,identity这个是指在创建表 ...

  8. 简述在ADO中使用接口的抽象数据提供程序以及ADO.NET数据提供程序工厂模型

    如何在ADO中使用接口的抽象数据提供程序 在cofig中 appSettings下,配置数据连接类型 <appSettings> <!--这个键值映射到枚举值中的某个值--> ...

  9. C#之使类型参数--泛型

    1.泛型是什么 泛型的就是“通用类型”,它可以代替任何的数据类型,使类型参数化,从而达到只实现一个方法就可以操作多种数据类型的目的. 2.为什么使用泛型 举一个比较两个数大小的例子: 以上例子实现in ...

  10. 分布式系统唯一ID的生成方案讨论

    在分布式系统下唯一id问题,就是id咋生成?比如分表分库,因为要是一个表分成多个表之后,每个表的id都是从1开始累加自增长,那是不对的.举个例子,一个表拆分为了2张表,每个表的id都从1开始累加,这个 ...