day 35 列出真分数序列

1.从1遍历到40;

2.若与40的最小公因数为1则输出

 

#include<iostream>

using namespace std;

int g(int m,int n){
if(m<m){swap(m,n);}
int t=1;
while(t){
t=m%n;
m=n;
n=t;
}
return m;
}


int main(){
int num=0;
for(int i=1;i<40;i++){
if(g(40,i)==1){printf("%2d/40 ",i);num++;}
if(num%4==0)printf("\n");
}
}

 

posted @ 2023-05-22 19:47  The-rich  阅读(13)  评论(0)    收藏  举报