递归法题解(效率低):
#include<stdio.h>
#include<stdlib.h>
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max(a, b) (((a) < (b)) ? (b) : (a))
unsigned long long search( unsigned long long x,unsigned long long y){
static unsigned long long count=0;
count+=min(x,y)*4;
if((max(x,y)-min(x,y))==0){
return count;
}
search(min(x,y),(max(x,y)-min(x,y)));
return count;
}
unsigned long long x,y;
int main(){
scanf("%llu%llu",&x,&y);
printf("%llu",search(x,y));
return 0;
}
迭代法题解:
#include<stdio.h>
#include<stdlib.h>
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max(a, b) (((a) < (b)) ? (b) : (a))
unsigned long long search( unsigned long long x,unsigned long long y){
static unsigned long long count=0;
count+=min(x,y)*4;
if((max(x,y)-min(x,y))==0){
return count;
}
search(min(x,y),(max(x,y)-min(x,y)));
return count;
}
unsigned long long x,y;
int main(){
scanf("%llu%llu",&x,&y);
printf("%llu",search(x,y));
return 0;
}
代码建议使用代码工具插入,不要用纯文本
哦哦哦哦,好的!到时候改一下。谢谢提醒!