SDUT 3917

UMR 现在手里有 n 张康纳的表情,最上面一张是玛吉呀巴库乃。现在 UMR 如果每次把最上面的 m 张牌移到最下面而不改变他们的顺序及朝向,那么至少经过多少次移动玛吉呀巴库乃才会又出现在最上面呢?

3917

Input

多组输入。

对于每组数据,输入以空格分隔的两个整数 n 和 m (1 <= n, m <= 10^9)。

Output

对于每组数据,输出一个整数,表示至少移动的次数。

Sample Input

54 12

Sample Output

9
  • 若x,y最大公约数为a,则x,y最小公倍数等于x*y/a,注意计算机里里面最好写成x/a*y,防止爆long long.
  • 记住gcd的写法。
 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #include<string.h>
 4 #include<math.h>
 5 #include<algorithm>
 6 #include<queue>
 7 #include<stack>
 8 #include<deque>
 9 #include<iostream>
10 using namespace std;
11 typedef long long  LL;
12 /* 迭代法(递推法):欧几里得算法,计算最大公约数 */
13 int gcd(int m, int n)
14 {
15     while(m>0)
16     {
17         int c = n % m;
18         n = m;
19         m = c;
20     }
21     return n;
22 }
23 
24 int main()
25 {
26     LL n,m;
27     while(scanf("%lld%lld",&n,&m)!=EOF)
28     {
29         int p=gcd(n,m);
30         printf("%d\n",n/p*m/m);
31     }
32     return 0;
33 }
View Code

 



转载于:https://www.cnblogs.com/daybreaking/p/9351437.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值