题目链接: 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. 安装window下的redis,redis可视化管理工具(Redis Desktop Manager)安装,基础使用,实例化项目

    以下包括内容: 一.redis下载安装,启动 二.Redis可视化管理工具(Redis Desktop Manager)安装 三.实例化项目 一.redis下载安装,启动 1,redis官方下载地址: ...

  2. SQLI LABS Basic Part(1-22) WriteUp

    好久没有专门练SQL注入了,正好刷一遍SQLI LABS,复习巩固一波~ 环境: phpStudy(之前一直用自己搭的AMP,下了这个之后才发现这个更方便,可以切换不同版本的PHP,没装的小伙伴赶紧试 ...

  3. 《前端之路》之 operator 操作符的优先级

    Github传送门,欢迎 Star - - Github地址,欢迎 Star

  4. Java进阶篇设计模式之四 -----适配器模式和桥接模式

    前言 在上一篇中我们学习了创建型模式的建造者模式和原型模式.本篇则来学习下结构型模式的适配器模式和桥接模式. 适配器模式 简介 适配器模式是作为两个不兼容的接口之间的桥梁.这种类型的设计模式属于结构型 ...

  5. 多元线性回归公式推导及R语言实现

    多元线性回归 多元线性回归模型 实际中有很多问题是一个因变量与多个自变量成线性相关,我们可以用一个多元线性回归方程来表示. 为了方便计算,我们将上式写成矩阵形式: Y = XW 假设自变量维度为N W ...

  6. Asp.NetCore轻松学-实现一个轻量级高可复用的RabbitMQ客户端

    前言 本示例通过对服务订阅的封装.隐藏细节实现.统一配置.自动重连.异常处理等各个方面来打造一个简单易用的 RabbitMQ 工厂:本文适合适合有一定 RabbitMQ 使用经验的读者阅读,如果你还没 ...

  7. 【JVM系列】一步步解析java执行内幕

    对于任何一门语言,要想达到精通的水平,研究它的执行原理(或者叫底层机制)不失为一种良好的方式.在本篇文章中,将重点研究java源代码的执行原理,即从程 序员编写JAVA源代码,到最终形成产品,在整个过 ...

  8. 【Oracle学习笔记】索引

    1 简介 1)索引是数据库对象之一,用于加快数据的检索,类似于书籍的索引.在数据库中索引可以减少数据库程序查询结果时需要读取的数据量,类似于在书籍中我们利用索引可以不用翻阅整本书即可找到想要的信息. ...

  9. DataTable克隆行

    DataRow Adr = ds.Tables[].NewRow(); Adr.ItemArray = (].Rows[].ItemArray.Clone(); ds.Tables[].Rows.Ad ...

  10. composer windows下安装

    composer windows安装  因要使用PhpSpreadsheet处理excel表格 选择composer安装 1. 下载Composer-Setup.exe 2.点击直接运行---选择ph ...