diff options
| author | Abigail <abigail@abigail.be> | 2020-11-08 19:40:05 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2020-11-08 19:40:05 +0100 |
| commit | 4e34dd5d0e89307aca9f4cd3bb6072c07f942ff1 (patch) | |
| tree | 52495c7853bf31c427ec26f500c66c5bed6753b4 /challenge-085/pkmnx/c++/ch-2/ch-2.cpp | |
| parent | 520db2cfca438cdc9a78932e5f479e28abee150b (diff) | |
| parent | ff7475c4559b1087f402725a7c526d3f780e3434 (diff) | |
| download | perlweeklychallenge-club-4e34dd5d0e89307aca9f4cd3bb6072c07f942ff1.tar.gz perlweeklychallenge-club-4e34dd5d0e89307aca9f4cd3bb6072c07f942ff1.tar.bz2 perlweeklychallenge-club-4e34dd5d0e89307aca9f4cd3bb6072c07f942ff1.zip | |
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-085/pkmnx/c++/ch-2/ch-2.cpp')
| -rw-r--r-- | challenge-085/pkmnx/c++/ch-2/ch-2.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/challenge-085/pkmnx/c++/ch-2/ch-2.cpp b/challenge-085/pkmnx/c++/ch-2/ch-2.cpp new file mode 100644 index 0000000000..bcb18bbd92 --- /dev/null +++ b/challenge-085/pkmnx/c++/ch-2/ch-2.cpp @@ -0,0 +1,47 @@ +#include <bits/stdc++.h> +#include <iostream> +#include <math.h> + +using namespace std; + +int main() { + + long n; + cin >> n; + + if ( n < 0 ) { + cout << "Input: " << n << " is not positive." << endl; + exit(0); + } + if ( n > INT_MAX ) { + cout << "Input: " << n << " is greater than INT_MAX: " << INT_MAX << endl; + exit(0); + } + + cout << "Input: " << n << endl; + + for ( int i = 2; i <= n; ++i ) { + if ( n % i == 0 ) { + + for ( int j = 2; j < INT_MAX; j++ ) { + + long ij = 1; + for ( int k = 0; k < j; k++ ) { + ij *= i; + if ( ij > n ) { break; } + } + if ( ij > n ) { break; } + + if ( ij == n ) { + cout << "Output: 1 as " << n << " = " << i << " ^ " << j << endl; + exit(0); + } + + } + + } + } + + cout << "Output: 0" << endl; + return 0; +} |
