Skip to content

Instantly share code, notes, and snippets.

@AndrewS097
Created March 10, 2019 08:21
Show Gist options
  • Save AndrewS097/2b65111d5b5d12c1de3498f80e7a8a49 to your computer and use it in GitHub Desktop.
Save AndrewS097/2b65111d5b5d12c1de3498f80e7a8a49 to your computer and use it in GitHub Desktop.
ACM Problem Solving for base of 3
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int runs, input, output;
int base=1;
int test_number= pow(215, 4);
//holds input numbers
cout << "How many inputs: " << endl;
cin>> runs;
//executes the loop of the entered amount of numbers
for (int i=0; i<=runs-1;i++){
cout << "Enter a value: " << endl;
cin>> input;
//runs the input through the mod test untill 3 is the end of the base
if (input >=3){
while(input%base !=3){
base++;
if (base>=test_number)//exits when there is no base
{
break;}
}
if (base>=test_number)
{cout << "No such base" << endl;
base=1;}
else {cout <<"The base is "<< base << endl;
base=1;
}
}
if (input < 3){
cout << "No such base" << endl;
base=1;
}
}
cout << "Program is complete" << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment