Last active
April 3, 2017 04:13
-
-
Save id4ehsan/894ab0bf0c282d03efe73337dea9420b to your computer and use it in GitHub Desktop.
Find Amicable Numbers
This file contains hidden or 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
// | |
// main.cpp | |
// Amicable | |
// | |
// Created by Ehsan Ghasemlou on 8/27/16. | |
// Copyright © 2016 Ehsan Ghasemlou. All rights reserved. | |
// | |
// XMMMWMMM@MMMMMMMMMi | |
// 7MMMMMMMMMMMMMMMMMMW, | |
// MMMMMMMMMM0W@@80MMMMMMi | |
// SMM@Xrrri:, ,rWMMM7 | |
// .MM2. ,8MMB | |
// XMW . i@MM: | |
// SM2.. iBMM: | |
// rM0. . :MMM. | |
// MM:rXr;:. .;SZZZaS; XMM | |
// XW700MMMM2rXZMBMB22X..M7,. | |
// :77.r2r@7Sr :7;2Xr7, ai,; | |
// rX; .,.. : . ... .;.i | |
// ,;i. ., , ..:,i, | |
// ;;:... :i ::, . ..,i:,. | |
// i;;:. . ;S77X;, ....,,: | |
// :;.... .:: ,.,.:: | |
// i:.:r7;i:;;77:....:;,S | |
// ,;:,:::ii:,.:,,,,;r @B, | |
// r;:,,,::,,,..,iSr :MWM2: | |
// 87;,,. .:XWX BB08B@M8X: | |
// :M7rrrr;;;;rXa0r 0W8ZZZZBMMMM0X, | |
// .XW ra8:;rXXSS2XXr;: ZW8ZZZZZBWB0WWM@ | |
// .78MMM7 ;7MX,iiiiiii;,iS SM8ZZZ8880W000088 | |
// ,rZMMMMM@M7..:ZWii;i;i;;i rr;@088Z880ZBB0Z088Z | |
// XMMMMMWWWWW@MM:,;SX;i;rr;r,,.r@0Z08008888B8008ZZ | |
//.aMM@WWWWW@WWWMMrr: iiii::,;, aBZ88008Z0Z80008ZZZ | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main(int argc, char** argv) { | |
int limit, n1, n2, chk; | |
int counter = 220; | |
printf("Enter limit:\n"); | |
scanf("%d", &limit); | |
while (counter < limit) | |
{ | |
int sum = 0; | |
int div = 0; | |
++counter; | |
while (div <= counter/2) | |
{ | |
++div; | |
if ( counter % div == 0 ) | |
sum += div; | |
} | |
chk = sum; | |
sum = div = 0; | |
while (div <= chk/2) | |
{ | |
++div; | |
if ( chk % div == 0 ) | |
sum += div; | |
} | |
if ( sum == counter ) | |
{ | |
if ( counter == chk ) continue; | |
n1 = counter; | |
if ( n1 == n2) continue; | |
n2 = chk; | |
printf("%d, %d\n",n1,n2); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment