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

题意:已知三个数a b c 的最小公倍数是 L ,现在告诉你 a b  L 求最小的 c ;

其实就是告诉你(最小公倍数LCM)LCM(x, y) = L 已知 x 和 L 求 最小的 y ;

L = LCM(x, y)=x*y/gcd(x, y);如果把x,y,L写成素因子之积的方式会很容易发现 L 就是 x 和 y 中素因子指数较大的那些数之积;

例如LCM(24, y) = 480,y最小为160

24 = 2^3 * 3 ;

480 = 2^5 * 3 * 5 ;

那么一个数的因子中一定含有 5 ,要最小,一定不含3,还有就是一定有2,因为是24*num/gcd(24, num),所以有2^5才能满足

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<vector>
using namespace std;
typedef long long LL;
const int oo = 0xfffffff;
const int N = ; LL gcd(LL a, LL b)
{
return b==?a:gcd(b, a%b);
} int main()
{
int T, t = ; scanf("%d", &T); while(T--)
{
LL a, b, L; scanf("%lld %lld %lld", &a, &b, &L); printf("Case %d: ", t++); LL x = a*b/gcd(a, b); if(L%x) puts("impossible");
else
{
LL y = L/x, r; /// x * y = L;逐步扩大 y,缩小 x; while(r = gcd(x, y), r!=)
{
x /= r;
y *= r;
}
printf("%lld\n", y);
}
}
return ;
}
/*
4 6 24
6 8 480
8
160
*/

LightOj 1215 - Finding LCM(求LCM(x, y)=L中的 y )的更多相关文章

  1. LightOj 1215 Finding LCM

    Discription LCM is an abbreviation used for Least Common Multiple in Mathematics. We say LCM (a, b, ...

  2. apt-get -y install中的-y是什么意思?

    是同意的意思.没有 -y的命令也可以执行,系统会提示你是否安装,输入y,回车,就会安装了 apt-get -y install这个指令则是跳过系统提示,直接安装.

  3. lightoj 1215

    lightoj 1215 Finding LCM 链接:http://www.lightoj.com/volume_showproblem.php?problem=1215 题意:已知 a, b, l ...

  4. Finding LCM LightOJ - 1215 (水题)

    这题和这题一样......只不过多了个数... Finding LCM LightOJ - 1215 https://www.cnblogs.com/WTSRUVF/p/9316412.html #i ...

  5. 1215 - Finding LCM

    1215 - Finding LCM   LCM is an abbreviation used for Least Common Multiple in Mathematics. We say LC ...

  6. BZOJ4833: [Lydsy1704月赛]最小公倍佩尔数(min-max容斥&莫比乌斯反演)(线性多项式多个数求LCM)

    4833: [Lydsy1704月赛]最小公倍佩尔数 Time Limit: 8 Sec  Memory Limit: 128 MBSubmit: 240  Solved: 118[Submit][S ...

  7. POJ-2429 GCD & LCM Inverse---给出gcd和lcm求原来两个数

    题目链接: https://cn.vjudge.net/problem/POJ-2429 题目大意: 给出两个数的gcd和lcm,求原来的这两个数(限定两数之和最小). 解题思路: 首先,知道gcd和 ...

  8. Solve Equation gcd(x,y)=gcd(x+y,lcm(x,y)) gcd(x,y)=1 => gcd(x*y,x+y)=1

    /** 题目:Solve Equation 链接:http://acm.hnust.edu.cn/JudgeOnline/problem.php?id=1643 //最终来源neu oj 2014新生 ...

  9. ATcoder E - Flatten 质因子分解求LCM

    题解:其实就是求n个数的lcm,由于数据特别大,求lcm时只能用质因子分解的方法来求. 质因子分解求lcm.对n个数每个数都进行质因子分解,然后用一个数组记录某个质因子出现的最大次数.然后累乘pow( ...

随机推荐

  1. BZOJ4435 : [Cerc2015]Juice Junctions

    最大流=最小割,而因为本题点的度数不超过3,所以最小割不超过3,EK算法的复杂度为$O(n+m)$. 通过分治求出最小割树,设$f[i][j][k]$表示最小割为$i$时,$j$点在第$k$次分治过程 ...

  2. 使用spring rest插入数据库时发生了 前言中不允许有内容 错误

    该错误一般是编码带来的问题,比如在请求post的时候,使用了application/x-www-form-urlencoded的content type 那么请求传过来的string则需要用urlDe ...

  3. 洛谷 P1991 无线通讯网 Label:最小生成树 || 二分

    题目描述 国防部计划用无线网络连接若干个边防哨所.2 种不同的通讯技术用来搭建无线网络: 每个边防哨所都要配备无线电收发器:有一些哨所还可以增配卫星电话. 任意两个配备了一条卫星电话线路的哨所(两边都 ...

  4. POJ 1279 Art Gallery(半平面交)

    题目链接 回忆了一下,半平面交,整理了一下模版. #include <cstdio> #include <cstring> #include <string> #i ...

  5. URAL 1303. Minimal Coverage(DP)

    题目链接 又是输出路径...这题完全受上题影响,感觉两个题差不多..用了基本上一样的算法写了,这题比较纠结,就是卡内存啊...5000*5000的数组开不了..然后没办法,水了好几次MLE,看了一下虎 ...

  6. 为什么C#不使用多继承?(from stackoverflow)

    简单地说:是因为该语言的设计者决定不使用. 基本上,.NET和Java的设计者不使用多继承(MI),是因为他们认为给语言加上多继承获得的好处较少,抵不上因此增加的复杂性. 1.不同的语言对于多继承如何 ...

  7. 构建json数据post到接口的若干条规则

    接受数据接口: public ActionResult PostDownloadLog(PostDownloadLog postDownloadLogs) PostDownLoadLogL类 publ ...

  8. HTML5_嵌套移动APP端的H5页面meta标签

    <meta charset="utf-8"> <meta content="width=device-width, initial-scale=1.0, ...

  9. Linux 下安装mysql 链接库

    1.mysql 客户端 开发 链接库 1.1)CentOS yum install mysql-devel

  10. upload控件上传json文件合并的两种方法

    方法一: byte[] byte1 = FileUpload1.FileBytes; byte[] byte2 = FileUpload2.FileBytes; byte[] a1 = Encodin ...