Advertisement
rawyon

Untitled

Mar 29th, 2013
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. bool perfect_sqr( unsigned long long );
  7. bool prime ( unsigned long long);
  8. void print( unsigned long long, unsigned );
  9. int main()
  10. {
  11.   unsigned long long triangle = 0, multipel, x = 0;
  12.   unsigned counter = 0;
  13.   while( counter <= 15)
  14.     {
  15.       triangle += ++x;
  16.       counter  = 2; // triangle
  17.      
  18.       for (unsigned long i = 2 ; i <= triangle/2; ++i )
  19.     {
  20.       if( prime(i) )
  21.         {
  22.           multipel = i;
  23.           while( triangle % multipel == 0 )
  24.         {
  25.           cout << counter++ << endl;
  26.           multipel *= i;
  27.         }
  28.         }      
  29.     }
  30.     }
  31.   print(triangle, counter);  
  32.  
  33.   return 0;
  34. }
  35. bool prime ( unsigned long long n )
  36. {
  37.   for( unsigned i = 2; i < sqrt(n); ++i )
  38.     {
  39.       if ( n % i == 0 )
  40.     return false;
  41.     }
  42.   return true;
  43. }
  44.  
  45. void print( unsigned long long triangle, unsigned counter )
  46. {
  47.   cout << "Det första talet som har minst " << counter << " delare är " << triangle << endl;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement