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()
- {
- int t, j;
- bool repeat = true;
- unsigned long long triangle = 0, multipel, x = 0;
- unsigned counter = 0;
- cout << "Skriv in ett kravet på minst antal delare!\n";
- cin >> t;
- cout << endl;
- while( counter <= t)
- {
- triangle += ++x;
- counter = 2; // triangle
- for (unsigned long i = 2 ; i <= triangle/2; ++i )
- {
- j = 2;
- if( prime(i) )
- {
- multipel = i;
- while( triangle % multipel == 0 )
- {
- counter++;
- while( repeat )
- {
- repeat = false;
- for( unsigned c = 2; c < multipel/2; ++c )
- {
- multipel = i;
- multipel *= j++;
- if( multipel % c == 0 )
- repeat = true;
- }
- }
- }
- }
- }
- }
- print(triangle, t);
- 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