Time Limit: 2000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu

[Submit]   [Go Back]   [Status]

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 (最小公倍数)的更多相关文章

  1. LOJ Finding LCM(math)

    1215 - Finding LCM Time Limit: 2 second(s) Memory Limit: 32 MB LCM is an abbreviation used for Least ...

  2. 1215 - Finding LCM

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

  3. Summary: gcd最大公约数、lcm最小公倍数算法

    欧几里德算法 欧几里德算法又称辗转相除法,用于计算两个整数a,b的最大公约数.其计算原理依赖于下面的定理: 定理:gcd(a,b) = gcd(b,a mod b) 证明:a可以表示成a = kb + ...

  4. Finding LCM LightOJ - 1215 (水题)

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

  5. LightOj 1215 - Finding LCM(求LCM(x, y)=L中的 y )

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1215 题意:已知三个数a b c 的最小公倍数是 L ,现在告诉你 a b  L 求最 ...

  6. 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 ...

  7. LightOj 1215 Finding LCM

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

  8. GCD(最大公约数)和LCM(最小公倍数)的求法

    GCD(最大公约数) (1)辗转相除法(欧几里得算法)(常用) 将两个数a, b相除,如果余数c不等于0,就把b的值给a,c的值给b,直到c等于0,此时最大公约数就是b (2)更相减损术 将两个书中较 ...

  9. gcd和exgcd和lcm

    Gcd▪ 欧几里得算法又称辗转相除法,用于计算两个正整数 a, b 的最大公约数.▪ 计算公式为 gcd(a,b) = gcd(b,a mod b).▪ 公式无需证明,记忆即可.▪ 如果要求多个数的最 ...

随机推荐

  1. informatica9 安装下载,安装教程 介质(文章和视频教程)(csdn讲师:Array)

    Informatica学习:  参考文献:视频参考地址:http://edu.csdn.net/course/detail/5034,ETL之informatica9通关班(第二期) 1.安装介质的获 ...

  2. 关于本地代码挂载到vm虚拟环境下运行

    第一步: 首先你得装个 VM 虚拟机  然后新建一个Linux虚拟环境(建议CentOS镜像)(PS:至于安装此处就省略.....) 第二步:启动虚拟机配置 lnmp (这里我们可以使用 lnmp的 ...

  3. Spring Cloud Netflix多语言/非java语言支持之Spring Cloud Sidecar

    Spring Cloud Netflix多语言/非java语言支持之Spring Cloud Sidecar 前言 公司有一个调研要做,调研如何将Python语言提供的服务纳入到Spring Clou ...

  4. mysql 索引B-Tree类型对索引使用的生效和失效情况详解

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt343 当人们谈论索引的时候,如果没有特别指明类型 ,那多半说的是 B-Tre ...

  5. js文件引用方式及其同步执行与异步执行

    详见: http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp74   任何以appendChild(scriptNode) 的方式引入 ...

  6. 闭锁——CountDownLatch

    一.概念 闭锁是一个同步工具类,主要用于等待其他线程活动结束后,再执行后续的操作.例如:在王者荣耀游戏中,需要10名玩家都准备就绪后,游戏才能开始. CountDownLatch是concurrent ...

  7. 制作Visual Studio 2017 (VS 2017) 离线安装包

    史上功能最强大的Visual Studio 2017版本发布,但是由于版本更新速度加快和与第三方工具包集成的原因,微软研发团队没有为这个版本提供离线下载的安装文件.如果用户处在一个与外网隔离的网络环境 ...

  8. KVM网页管理工具WebVirtMgr部署

    KVM-WebVirtMgr 0ther https://github.com/retspen/webvirtmgr/wiki System Optimization(Only CentOS6.X) ...

  9. CentOS7中将home迁移到/下的命令 CentOS7中将home迁移到/下的命令

    # mkdir -p /backup # cp -r /home/* /backup # umount /home #  df -hl # fdisk -l # lvremove /dev/cento ...

  10. Sqli-Labs学习总结一

    题目1-20 github地址 前言 以前对于SQL注入,就是先判断下能不能注入,可以的话先试着联合查询,不行的话再上SQLMap,去年寒假拿了一本<SQL注入攻击与防御>,拿回家,看了几 ...