-
-
Save kaiware/7652747 to your computer and use it in GitHub Desktop.
Nまでの友愛数の組を表示するプログラム
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#define N 100000 | |
int div_sum(int x){ | |
int i; | |
int sum = 0; | |
for(i = 1; i < x; i++){ | |
if(x % i == 0){ | |
sum += i; | |
} | |
} | |
return sum; | |
} | |
int main(){ | |
int i; | |
int a, b; | |
for(i = 2; i < N; i++){ | |
a = div_sum(i); | |
if(a > i){ | |
b = div_sum(a); | |
if(b == i){ | |
printf("(%d, %d)\n", i, a); | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment