mirror of
https://bitbucket.org/Mattrixwv/projecteulercpp.git
synced 2025-12-06 17:13:59 -05:00
71 lines
2.8 KiB
C++
71 lines
2.8 KiB
C++
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem29.hpp
|
|
//Matthew Ellison
|
|
// Created: 10-06-19
|
|
//Modified: 07-02-21
|
|
//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) 2021 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
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
#ifndef PROBLEM29_HPP
|
|
#define PROBLEM29_HPP
|
|
|
|
|
|
#include <cinttypes>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <gmpxx.h>
|
|
#include "Problem.hpp"
|
|
|
|
|
|
class Problem29 : public Problem{
|
|
private:
|
|
//Variables
|
|
//Static variables
|
|
static unsigned int BOTTOM_A; //The lowest possible value for a
|
|
static unsigned int TOP_A; //The highest possible value for a
|
|
static unsigned int BOTTOM_B; //The lowest possible value for b
|
|
static unsigned int TOP_B; //The highest possible value for b
|
|
//Instance variables
|
|
std::vector<mpz_class> unique; //Holds all values in powers, except repeats
|
|
public:
|
|
//Constructor
|
|
Problem29();
|
|
//Operational functions
|
|
virtual void solve(); //Solve the problem
|
|
virtual void reset(); //Reset the problem so it can be run again
|
|
//Gets
|
|
virtual std::string getResult()const; //Return a string with the solution to the problem
|
|
unsigned int getBottomA() const; //Returns the lowest possible value for a
|
|
unsigned int getTopA() const; //Returns the highest possible value for a
|
|
unsigned int getBottomB() const; //Returns the lowest possible value for b
|
|
unsigned int getTopB() const; //Returns the highest possible value for b
|
|
std::vector<mpz_class> getUnique() const; //Returns a vector of all the unique values for a^b
|
|
size_t getNumUnique() const; //Returns the number of unique values for a^b
|
|
};
|
|
|
|
|
|
/* Results:
|
|
The number of unique values generated by a^b for 2 <= a <= 100 and 2 <= b <= 100 is 9183
|
|
It took an average of 1.651 seconds to run this problem over 100 iterations
|
|
*/
|
|
|
|
|
|
#endif //PROBLEM29_HPP
|