C
来源:互联网 发布:linux vim 删除 编辑:程序博客网 时间:2024/06/07 03:57
C - 又见GCD
有三个正整数a,b,c(0<a,b,c<10^6),其中c不等于b。若a和c的最大公约数为b,现已知a和b,求满足条件的最小的c。
26 212 4
48
#include <iostream>#include <cstdio>int gcd(int a,int b){while(a%b){int r=a%b;a=b;b=r;}return b;}int main(){int n;scanf("%d",&n);while(n--){int a,b,c;scanf("%d %d",&a,&b);c=2*b;while(gcd(a,c)!=b)c+=b;printf("%d\n",c);}return 0;
}
阅读全文
0 0
- c
- c
- c
- c
- C
- c
- c
- c
- C+
- c
- C
- c
- c
- c
- C
- C
- c
- C
- HDOJ 1160 FatMouse's Speed (结构体排序+动态规划)详解
- scikit-learn学习笔记(二)load_files加载自己的文件
- 欢迎使用CSDN-markdown编辑器
- 动态增加 ListView 的 item,且 item 中有 EditText
- linux内核修炼之道(20170727)
- C
- 数字和字符串类型
- day13(StringBuffer,Arrays,基本类型包装类)
- SDUT-数据结构实验之链表九:双向链表
- mq-2-多broker配置
- 4. Median of Two Sorted Arrays
- mdsplus之通过C和C++远程访问
- maven基础知识总结
- 1036. 跟奥巴马一起编程