Humble numbers | Rosetta Code | #7

URL to the problem page: http://rosettacode.org/wiki/Humble_numbers


Humble numbers are positive integers which have no prime factors > 7.
Humble numbers are also called 7-smooth numbers, and sometimes called highly composite, although this conflicts with another meaning of highly composite numbers.

Show the first 50 humble numbers.


#include <iostream>
using namespace std;

bool primecheck(int a) {
    int counter = 0;
    for (int i = 2; i <= (a / 2); i++) {
        if (a % i == 0) {
            counter++;
            break;
        }
    }
    if (counter == 0) {
        return 1;
    }
    else {
        return 0;
    }
}

int main()
{
    int counter = 0, counter2;

    cout << "First 50 humble numbers are:" << endl;
    for (int i = 1; counter < 50; i++) {
        counter2 = 0;
        for (int j = 2; j <= (i / 2); j++) {
            if (i % j == 0 && j > 7 && primecheck(j) == 1 || primecheck(i) == 1 && i > 7) {
                counter2++;
                break;
            }
        }
        if (counter2 == 0) {
            cout << i << ", ";
            counter++;
        }
    }
    cout << endl;
    return 0;
}



Comments

My photo
Ercan Tomac
instagram.com/ercantomac