Finding LCM (最小公倍数)
| Time Limit: 2000MS | Memory Limit: 32768KB | 64bit IO Format: %lld & %llu |
Description
LCM is an abbreviation used for Least Common Multiple in Mathematics. We say LCM (a, b, c) = L if and only if L is the least integer which is divisible bya, b and c.
You will be given a, b and L. You have to find c such that LCM (a, b, c) = L. If there are several solutions, print the one where c is as small as possible. If there is no solution, report so.
Input
Input starts with an integer T (≤ 325), denoting the number of test cases.
Each case starts with a line containing three integers a b L (1 ≤ a, b ≤ 106, 1 ≤ L ≤ 1012).
Output
For each case, print the case number and the minimum possible value of c. If no solution is found, print 'impossible'.
Sample Input
3
3 5 30
209475 6992 77086800
2 6 10
Sample Output
Case 1: 2
Case 2: 1
Case 3: impossible
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
long long gcd(long long x,long long y)
{
if(y==)return x;
return gcd(y,x%y);
}
int main()
{
long long a,b,l;
int n,i,j;
cin>>n;
for(i=; i<=n; i++)
{
cin>>a>>b>>l;
a=a/gcd(a,b)*b;
if(l%a)
{
printf("Case %d: ",i);
printf("impossible\n");
}
else
{
b=l/a;
while(gcd(a,b)!=)
{
long long t=gcd(a,b);
b*=t;
a/=t;
}
printf("Case %d: ",i);
printf("%lld\n",b);
}
}
}
Finding LCM (最小公倍数)的更多相关文章
- LOJ Finding LCM(math)
1215 - Finding LCM Time Limit: 2 second(s) Memory Limit: 32 MB LCM is an abbreviation used for Least ...
- 1215 - Finding LCM
1215 - Finding LCM LCM is an abbreviation used for Least Common Multiple in Mathematics. We say LC ...
- Summary: gcd最大公约数、lcm最小公倍数算法
欧几里德算法 欧几里德算法又称辗转相除法,用于计算两个整数a,b的最大公约数.其计算原理依赖于下面的定理: 定理:gcd(a,b) = gcd(b,a mod b) 证明:a可以表示成a = kb + ...
- Finding LCM LightOJ - 1215 (水题)
这题和这题一样......只不过多了个数... Finding LCM LightOJ - 1215 https://www.cnblogs.com/WTSRUVF/p/9316412.html #i ...
- LightOj 1215 - Finding LCM(求LCM(x, y)=L中的 y )
题目链接:http://lightoj.com/volume_showproblem.php?problem=1215 题意:已知三个数a b c 的最小公倍数是 L ,现在告诉你 a b L 求最 ...
- gcd,最大公约数,lcm,最小公倍数
int gcd(int a,int b){ ?a:gcd(b,a%b); } 关于lcm,若写成a*b/gcd(a,b) ,a*b可能会溢出! int lcm(int a,int b){ return ...
- LightOj 1215 Finding LCM
Discription LCM is an abbreviation used for Least Common Multiple in Mathematics. We say LCM (a, b, ...
- GCD(最大公约数)和LCM(最小公倍数)的求法
GCD(最大公约数) (1)辗转相除法(欧几里得算法)(常用) 将两个数a, b相除,如果余数c不等于0,就把b的值给a,c的值给b,直到c等于0,此时最大公约数就是b (2)更相减损术 将两个书中较 ...
- gcd和exgcd和lcm
Gcd▪ 欧几里得算法又称辗转相除法,用于计算两个正整数 a, b 的最大公约数.▪ 计算公式为 gcd(a,b) = gcd(b,a mod b).▪ 公式无需证明,记忆即可.▪ 如果要求多个数的最 ...
随机推荐
- 使用 Palette 让你的 UI 色彩与内容更贴合
版权声明: 本账号发布文章均来自公众号,承香墨影(cxmyDev),版权归承香墨影所有. 每周会统一更新到这里,如果喜欢,可关注公众号获取最新文章. 未经允许,不得转载. 一.前言 今天介绍一个 An ...
- wowza拉流和推流接口备忘
拉流接口地址:https://www.wowza.com/docs/stream-management-query-examples# 推流接口地址:https://www.wowza.com/doc ...
- xcode模拟器不显示键盘解决方案
当我们使用Xcode进行开发的时候,并不是所有的时候都需要将代码运行在iPhone,有时候模拟器就可以解决这些问题, 但是当你使用模拟器的时候会发现,在TextFiled中输入信息时,如果你是用模拟器 ...
- 实时监听文本框输入 oninput、onchange与onpropertychange事件的用法和区别
前端页面开发的很多情况下都需要实时监听文本框输入,比如腾讯微博编写140字的微博时输入框hu9i动态显示还可以输入的字数.过去一般都使用onchange/onkeyup/onkeypress/onke ...
- CSS中的路径裁剪样式clip-path
前面的话 CSS借鉴了SVG裁剪的概念,设置了clip-path样式,本文将详细介绍路径裁剪clip-path 概述 clip-path属性可以防止部分元素通过定义的剪切区域来显示,仅通过显示的特殊区 ...
- PHP初入--表单元素
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...
- 自制裸眼3D图【推荐】
Welcome to the World of Hidden 3D Stereograms.欢迎进入隐身3D图的世界! 网址:http://hidden-3d.com 裸眼立体图是什么? 立体图是立体 ...
- Socket通信中AF_INET 和 AF_UNIX域的区别
转载:http://blog.csdn.net/sandware/article/details/40923491 1. AF_INET域socket通信过程 典型的TCP/IP四层模型的通信过程. ...
- 个人作业(2)---英语学习APP案例分析
第一部分 调研, 评测 1.下载并使用,描述最简单直观的个人第一次上手体验. PC上的必应词典主页面与其他英语学习APP类似,一些英文读物的推送,但是每日阅读需要去浏览器去看有点不太方便,我觉得直接在 ...
- Java学习10——package和import
package和import语句 为了便于管理大型软件系统中数目众多的类,解决类的命名冲突问题,Java引入包(package)机制,提供类的多重类命名空间,使用时,import引入相应package ...