Files
ProjectEulerCPP/Headers/Problem29.hpp
2020-07-08 20:38:37 -04:00

64 lines
2.3 KiB
C++

//ProjectEuler/C++/Headers/Problem29.hpp
//Matthew Ellison
// Created: 10-06-19
//Modified: 10-06-19
//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
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 <string>
#include <cinttypes>
#include <vector>
#include <gmpxx.h>
#include "Problem.hpp"
class Problem29 : public Problem{
private:
static const unsigned int BOTTOM_A = 2; //The lowest possible value for a
static const unsigned int TOP_A = 100; //The highest possible value for a
static const unsigned int BOTTOM_B = 2; //The lowest possible value for b
static const unsigned int TOP_B = 100; //The highest possible value for b
std::vector<mpz_class> unique; //Holds all values in powers, except repeats
public:
Problem29();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
unsigned int getBottomA() const;
unsigned int getTopA() const;
unsigned int getBottomB() const;
unsigned int getTopB() const;
std::vector<mpz_class> getUnique() const;
};
/* Results:
The number of unique values generated by a^b for 2 <= a <= 100 and 2 <= b <= 100 is 9183
It took 1.464 seconds to solve this problem.
*/
#endif //PROBLEM29_HPP