Created
September 19, 2019 01:46
-
-
Save ssysm/ebcc0c4eeb5a31c84e67addc39d6e318 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <math.h> | |
using namespace std; | |
bool isNumExist(vector < double > & vec, double num); | |
int getDistinctPower(int a_min_base, int a_max_base, int b_min_power, int b_max_power); | |
void main() { | |
int dp = getDistinctPower(2, 100, 2, 100); | |
cout << dp << endl; | |
} | |
bool isNumExist(vector < double > & vec, double num) { | |
for (double & x: vec) { //step each vector | |
if (x == num) { | |
return true; | |
} | |
} | |
return false; | |
} | |
int getDistinctPower(int a_min_base, int a_max_base, int b_min_power, int b_max_power) { | |
vector < double > products; | |
// compute and popluate vector | |
for (double base = a_min_base; base <= a_max_base; base++) { | |
for (double power = b_min_power; power <= b_max_power; power++) { | |
double prod = pow(base, power); | |
if (!isNumExist(products, prod)) { // does number exist? | |
products.push_back(prod); | |
} | |
} | |
} | |
// return vector size | |
return products.size(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment