单点时限: 2.0 sec
内存限制: 256 MB
给定两个正整数 (值范围为 1 - 109),输出它们的最大公约数。
第 1 行:一个整数 $T$ ($1 \le T \le 10$) 为问题数。
接下来共 T 行,每行两个整数,中间由一个空格分隔。
对于每个问题,输出一行问题的编号(0 开始编号,格式:case #0: 等)。
然后对应每个问题在一行中输出两个正整数的最大公约数。
3 1 1 2 3 12 18
case #0:
1
case #1:
1
case #2:
6
Hints
程序:
/*/////////////////////////////////////////////////////*/
int gcd(int a, int b)
{ //TODO: your definition
}
/*/////////////////////////////////////////////////////*/
/***************************************************************/
/*                                                             */
/*  DON'T MODIFY THIS FILE ANYWAY!                             */
/*                                                             */
/***************************************************************/
#include <stdio.h>
//********** Specification of gcd **********
int gcd(int a, int b);
/* PreCondition:
a and b are integers ranging from 1 to 1000,000,000
PostCondition:
return the greatest common divisor of a and b
*/
void solve()
{
int a,b; scanf("%d%d",&a,&b);
//********** gcd is called here **********
printf("%d\\n",gcd(a,b));
//****************************************
}
int main()
{  int i,t;
scanf("%d\\n",&t);
for (i=0;i<t;i++)
{ printf("case #%d:\\n",i);
solve();
}
return 0;
}
            | 题目 | 计分 | 
|---|---|
| A | 100 | 
| B | 100 | 
| C | 100 | 
| D | 100 | 
| E | 100 | 
| F | 100 | 
| G | 100 | 
| H | 100 | 
| I | 100 | 
| J | 100 | 
| K | 100 | 
| L | 100 | 
| M | 100 | 
| N | 100 | 
| O | 100 | 
| P | 100 | 
| Q | 100 | 
| R | 100 |