Project Euler Homework
|
00001 00009 #include <iostream> 00010 using namespace std; 00011 00012 unsigned long 00013 lcm (unsigned long a, int b) 00014 { 00015 unsigned long large, small, remainder; 00016 if (a > b) 00017 { 00018 large = a; 00019 small = b; 00020 } 00021 else 00022 { 00023 large = b; 00024 small = a; 00025 } 00026 00027 do 00028 { 00029 remainder = large % small; 00030 large = small; 00031 small = remainder; 00032 } 00033 while (small >= 1); 00034 //gcd(a,b)= large 00035 00036 return a * b / large; 00037 } 00038 00039 int 00040 main () 00041 { 00042 unsigned long x = 1; 00043 for (int k = 1; k <= 20; k++) 00044 { 00045 x = lcm (x, k); 00046 cout << k <<" "<< x << endl; 00047 } 00048 return 0; 00049 } 00050