题目链接: 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. 从壹开始前后端分离 [ Vue2.0+.NET Core2.1] 二十四║ Vuex + JWT 实现授权验证登录

    壹周回顾 哈喽,又是元气满满的一个周一,又与大家见面了,周末就是团圆节了,正好咱们的前后端也要团圆了,为什么这么说呢,因为以后的开发可能就需要前后端一起了,两边也终于会师了,还有几天Vue系列就基本告 ...

  2. 辅助模式最终考验的是想象力,先来看看怎么用!| Accessibility

    一.序 Hi,大家好,我是承香墨影! Android 的辅助模式(Accessibility)功能非常的强大.基本上被获取到授权之后,可以监听手机上的任何事件,例如:屏幕点击.窗口的变化.以及模拟点击 ...

  3. java游戏开发杂谈 - java是什么

    java是一门编程语言, 它有三个开发平台:j2ee.j2se. j2me.(其实android也算一个了)      j2ee, 也就是web开发,比如网站.各类管理系统,主要是围绕数据库.网页等进 ...

  4. ASP.NET Core - 开篇

    由来 ASP.NET Core 是一个跨平台的高性能开源框架,ASP.NET Core第一次出现在我们眼前是以 ASP.NET vNext 命名的,然后又重新命名为ASP.NET 5,为了表明它并不是 ...

  5. C#工具:WPF分页

    1.使用ItemsControl控件 <UserControl x:Class="SunCreate.Vipf.Client.UI.CityDoor.PageControl" ...

  6. C# WebRequest.Create 锚点“#”字符问题

    背景 在与后台API接口对接时,如将网页Url作为参数请求数据时,如果是锚点参数,则会丢失. 锚点参数 请求通过WebRequest.Create创建一个WebRequest: var uri = & ...

  7. 2017-2018年Scrum状态调查报告

    HOW SCRUM IS USED 在2017年的报告中,Scrum的应用范围在扩大,已经从其发源的IT部门扩展到了相距甚远的业务部门.2017-2018年度报告的其中一个主要目标就是关注更广泛的敏捷 ...

  8. ssh登录错误ECDSA host key for ip has changed解决方案

    当我们使用ssh root@ip登录Linux服务器时,服务器报错: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WAR ...

  9. Web前端 前端相关书籍推荐

    一.HTML篇 1)<精通HTML> 2)<HTML5秘籍> 3)<HTML5权威指南> 4)<Head First HTML5 Programming(中文 ...

  10. java 设计模式 ---- 单例模式

    只产生一个实例, 所以要使用静态方法对外暴露对象(如果使用反射技术, 也能调用私有的构造方法) 懒汉模式 并发时还是可能会产生多个实例, 所以同步处理 public class User{ priva ...