Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- bool perfect_sqr( unsigned long long );
- bool prime ( unsigned long long);
- void print( unsigned long long, unsigned );
- int main()
- {
- unsigned long long triangle = 0, multipel, x = 0;
- unsigned counter = 0;
- while( counter <= 15)
- {
- triangle += ++x;
- counter = 2; // triangle
- for (unsigned long i = 2 ; i <= triangle/2; ++i )
- {
- if( prime(i) )
- {
- multipel = i;
- while( triangle % multipel == 0 )
- {
- cout << counter++ << endl;
- multipel *= i;
- }
- }
- }
- }
- print(triangle, counter);
- return 0;
- }
- bool prime ( unsigned long long n )
- {
- for( unsigned i = 2; i < sqrt(n); ++i )
- {
- if ( n % i == 0 )
- return false;
- }
- return true;
- }
- void print( unsigned long long triangle, unsigned counter )
- {
- cout << "Det första talet som har minst " << counter << " delare är " << triangle << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement