project-euler

https://projecteuler.net/
Log | Files | Refs | README

EulerUtility.h (1896B)


      1 #include <cmath>
      2 #include <cstdint>
      3 #include <string>
      4 #include <vector>
      5 
      6 #include <boost/multiprecision/cpp_int.hpp>
      7 
      8 typedef long long unsigned int llui;
      9 typedef long long int ll;
     10 
     11 using namespace boost::multiprecision;
     12 
     13 class EulerUtility
     14 {
     15 public:
     16     static int multiply(int x, int y);
     17     static std::vector<int> getPrimesUnderCeiling(int ceiling);
     18     static std::vector<int> getPrimesUnderCeilingIndexed(int ceiling);
     19     static std::vector<int> tokenizer(std::string s, char delim);
     20     static std::vector<std::string> strTokenizer(std::string s, char delim);
     21     static int sumOfDivisors(int n);
     22     static std::vector<int> factorialDigits(int n);
     23     static std::vector<int> powerDigits(int n, int p);
     24     static int factorial(int n);
     25     static cpp_int bigFactorial(cpp_int n);
     26     static cpp_int choose(int n, int k);
     27     static bool isPerfectSquare(llui n);
     28     static bool isPerfectCube(llui n);
     29     static std::vector<int> intToDigits(int n);
     30     static std::vector<int> lluiToDigits(llui n);
     31     static std::vector<int> BigIntToDigits(cpp_int n);
     32     static int digitsToInteger(std::vector<int> digits);
     33     static llui digitsTollui(std::string s);
     34     static bool hasUniqueDigits(int n, bool allowZero);
     35     static bool isPrime(ll n, int iteration);
     36     static bool isPrime(cpp_int& n);
     37     static bool isTriangle(int n);
     38     static bool isPentagonal(llui n);
     39     static std::vector<std::string> openWordFile(std::string filename);
     40     static cpp_int power(cpp_int i, int p);
     41     static int digitalRoot(int n);
     42     static int digitalRoot(cpp_int n);
     43     static std::vector<int> intersect(std::vector<int>& a, std::vector<int>& b);
     44     static std::vector<int> getFigurates(int sides, int floor, int ceiling);
     45     static llui gcd(llui a, llui b);
     46     static llui binary_gcd(llui a, llui b);
     47     static llui phi(int n, std::vector<int> &primes, std::vector<int> &primesIndexed);
     48 };