Files
ProjectEulerCPP/headers/Problems/Problem38.hpp
2021-10-22 19:28:04 -04:00

57 lines
2.0 KiB
C++

//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem38.hpp
//Matthew Ellison
// Created: 10-10-21
//Modified: 10-10-21
//What is the largest 1-9 pandigital number that can be formed as the concatenated product of an integer with 1, 2, ... n where n > 1
/*
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/>.
*/
#pragma once
#include <cinttypes>
#include <string>
#include "Problem.hpp"
class Problem38 : public Problem{
private:
//Variables
//Static variables
static int HIGHEST_POSSIBLE_NUM; //The highest number that needs to be checked for a 1-9 pandigital
//Instance variables
uint64_t largestNum; //The number passed to the executeFormula function that returns the largest pandigital
uint64_t pandigital; //The largest pandigital number found
//Functions
std::string executeFormula(int num); //Take the number and add its multiples to a string to return
public:
//Functions
//Constructor
Problem38();
//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; //Returns a string with the solution to the problem
uint64_t getLargestNum() const; //Returns the largest number
uint64_t getPandigital() const; //Returns the pandigital of the number
};
/* Results:
The largest appended product pandigital is 932718654
It took 740.729 microseconds to solve this problem.
*/