Euler Problem: Solution of Problem-5 in C++

#include 

#define X 20

using namespace std;

long hcf ( const long & small_num, const long & big_num ) {
    if ( small_num > big_num ) {
        return hcf ( big_num, small_num );
    }
    else {
        if ( big_num % small_num == 0 ) {
            return small_num;
        }
        else {
            return hcf ( big_num % small_num, small_num );
        }
    }
}

int main ( int argc, char *argv[] ) {
    long result = 1;
    long temp_hcf;
    for ( int i = 1; i <= X; i++ ) {
        temp_hcf = hcf ( result, i );
        result /= temp_hcf;
        result *= i;
    }
    cout << "Result = " << result << endl;
    return 0;
}

// Result = 232792560

Published by

Sreejith

A strong believer of: 1. Knowledge is power 2. Progress comes from proper application of knowledge 3. Reverent attains wisdom 4. For one's own salvation, and for the welfare of the world

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s