mirror of
https://bitbucket.org/Mattrixwv/projecteulercpp.git
synced 2025-12-06 17:13:59 -05:00
Updated comments and made sure style was consistent
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
//ProjectEuler/C++/Source/Problem29.cpp
|
||||
//ProjectEuler/ProjectEulerCPP/Source/Problem29.cpp
|
||||
//Matthew Ellison
|
||||
// Created: 10-06-19
|
||||
//Modified: 10-06-19
|
||||
//Modified: 07-09-20
|
||||
//How many distinct terms are in the sequence generated by a^b for 2 <= a <= 100 and 2 <= b <= 100?
|
||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/myClasses
|
||||
//This file contains a header from the gmp library. The library is used for large integers.
|
||||
//You can find more information about them at https://gmplib.org/
|
||||
//When compiling this file you need to have the gmp library installed as well as linking the libraries to your executable using the -lgmpxx and -lgmp flags
|
||||
/*
|
||||
Copyright (C) 2019 Matthew Ellison
|
||||
Copyright (C) 2020 Matthew Ellison
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
@@ -34,9 +34,20 @@
|
||||
#include "Algorithms.hpp"
|
||||
|
||||
|
||||
//The lowest possible value for a
|
||||
unsigned int Problem29::BOTTOM_A = 2;
|
||||
//The highest possible value for a
|
||||
unsigned int Problem29::TOP_A = 100;
|
||||
//The lowest possible value for b
|
||||
unsigned int Problem29::BOTTOM_B = 2;
|
||||
//The highest possible value for b
|
||||
unsigned int Problem29::TOP_B = 100;
|
||||
|
||||
//Constructor
|
||||
Problem29::Problem29() : Problem("How many distict terms are in the sequence generated by a^b for 2 <= a <= 100 and 2 <= b <= 100?"){
|
||||
}
|
||||
|
||||
//Solve the problem
|
||||
void Problem29::solve(){
|
||||
//If the problem has already been solved do nothing and end the function
|
||||
if(solved){
|
||||
@@ -66,6 +77,13 @@ void Problem29::solve(){
|
||||
solved = true;
|
||||
}
|
||||
|
||||
//Reset the problem so it can be run again
|
||||
void Problem29::reset(){
|
||||
Problem::reset();
|
||||
unique.clear();
|
||||
}
|
||||
|
||||
//Return a string with the solution to the problem
|
||||
std::string Problem29::getString() const{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -78,6 +96,7 @@ std::string Problem29::getString() const{
|
||||
return results.str();
|
||||
}
|
||||
|
||||
//Returns the lowest possible value for a
|
||||
unsigned int Problem29::getBottomA() const{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -86,6 +105,7 @@ unsigned int Problem29::getBottomA() const{
|
||||
return BOTTOM_A;
|
||||
}
|
||||
|
||||
//Returns the highest possible value for a
|
||||
unsigned int Problem29::getTopA() const{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -94,6 +114,7 @@ unsigned int Problem29::getTopA() const{
|
||||
return TOP_A;
|
||||
}
|
||||
|
||||
//Returns the lowest possible value for b
|
||||
unsigned int Problem29::getBottomB() const{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -102,6 +123,7 @@ unsigned int Problem29::getBottomB() const{
|
||||
return BOTTOM_B;
|
||||
}
|
||||
|
||||
//Returns the highest possible value for b
|
||||
unsigned int Problem29::getTopB() const{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -110,6 +132,7 @@ unsigned int Problem29::getTopB() const{
|
||||
return TOP_B;
|
||||
}
|
||||
|
||||
//Returns a vector of all the unique values for a^b
|
||||
std::vector<mpz_class> Problem29::getUnique() const{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -117,8 +140,3 @@ std::vector<mpz_class> Problem29::getUnique() const{
|
||||
}
|
||||
return unique;
|
||||
}
|
||||
|
||||
void Problem29::reset(){
|
||||
Problem::reset();
|
||||
unique.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user