求最大公约数

来源:互联网 发布:js怎么添加节点 编辑:程序博客网 时间:2024/06/06 08:59

Description

Luke刚数完素数,现在开始求a和b的最大公约数了。

Input

输入有多组,每组输入为两个整数a b(2<=a<=b<=10000000000000)

Output

对于每组输入,先输出” Case T:”,T从1开始。然后输出a和b的最大公约数

Sample Input

12 8
36 46

Sample Output

Case 1:
4
Case 2:
2

Source

Luke


#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>long long gcd(long long int a,long long int b){    return a%b==0?b:gcd(b,a%b);}int main(){    long long a,b;    int index=1;    while(~scanf("%lld%lld",&a,&b))    {        printf("Case %d:\n",index++);        printf("%lld\n",gcd(a,b));    }    return 0;}


原创粉丝点击