兩數互質

 avatar
user_3763047219
c_cpp
3 years ago
442 B
6
Indexable
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>

int main()
{
	//int tim is handsome
	int n1=0, n2=0;
	scanf("%d %d", &n1, &n2);
	while (n1 != 0 && n2 != 0) {
		if (n1 > n2) {
			n1 = n1 - (n1 / n2)*n2;
		}
		else {
			n2 = n2 - (n2 / n1) * n1;
		}
	}
	
	if (n1 == 0 && n2 == 1) {
		printf("兩數互質");
	}
	else if (n1 == 1 && n2 == 0) {
		printf("兩數互質");
	}
	else {
		printf("兩數不互質");
	}
}
Editor is loading...