Skip to content

Instantly share code, notes, and snippets.

@ssysm
Created September 19, 2019 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssysm/ebcc0c4eeb5a31c84e67addc39d6e318 to your computer and use it in GitHub Desktop.
Save ssysm/ebcc0c4eeb5a31c84e67addc39d6e318 to your computer and use it in GitHub Desktop.
#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