数论-北大-1597

1 view
Skip to first unread message

china_sjc

unread,
Aug 6, 2008, 5:41:19 AM8/6/08
to 中国矿业大学徐海学院算法课程
#include<stdio.h>
int main()
{
int stp,mod,n;
while(scanf("%d %d",&stp,&mod)==2)
{
if(stp>=1&&mod<=1000000)
{
printf("%10d%10d ",stp,mod);
n=stp>mod?mod:stp;
for(;n>=1;n--)if(stp%n==0&&mod%n==0)break;
if(n==1)printf("Good Choice\n");else printf("Bad Choice\n");
printf("\n");
}
}
return 0;
}

china_sjc

unread,
Aug 6, 2008, 6:30:20 AM8/6/08
to 中国矿业大学徐海学院算法课程
#include"stdio.h"
void main()
{
long m,n,k,i;
while(scanf("%ld%ld",&m,&n)!=-1)
{ printf("%10ld%10ld ",m,n);
k=1;
for(i=2;i<=(m>n?n:m);i++)
{
if(m%i==0&&n%i==0)
k=i;
}
if(k==1)
printf("Good Choice\n\n");
else
printf("Bad Choice\n\n");

}
}

china_sjc

unread,
Aug 6, 2008, 11:23:26 PM8/6/08
to 中国矿业大学徐海学院算法课程
#include<stdio.h>
int main()
{
int stp,mod,n;
while(scanf("%d %d",&stp,&mod)==2)
{
if(stp>=1&&mod<=1000000)
{
printf("%10d%10d ",stp,mod);
n=stp>mod?mod:stp; //n取stp和mod中的小值
for(;n>=1;n--)//逐个测试
if(stp%n==0&&mod%n==0)//同时能被整除
break;
if(n==1)//从n到2的数都不能同时被整除,为好选择
Reply all
Reply to author
Forward
0 new messages