[Zhengqing] [1778] The Monk's Troubles 4 - How Much Combat Power

Problem Description

Loading...

Problem Analysis

If you only read the statement and not the data, you might easily mistake it for a product.
(Though it shouldn’t be that confusing… -.-)
The problem asks for the least common multiple.
Just divide the product of the two numbers by their greatest common divisor.

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include<stdio.h>
#include<math.h>
#include<string.h>
int main() {
	int m,n,ji;
	while(scanf("%d %d",&m,&n)!=EOF) {
		ji=m*n;
		while(m!=n) {
			if(m>n)
				m-=n;
			if(n>m)
				n-=m;
		}
		printf("%d\n",ji/m);
	}
	return 0;
}

Problem link: [ZZULI] [1778] Monk’s Troubles 4 — How Much Combat Power

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...