Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "../TTMATH/ttmath.h" // for 128 uints
- #define uint128 ttmath::UInt<2> // define a 128 bit unsigned
- int main()
- {
- std::cout.sync_with_stdio(false);
- const uint128 wanted_result = 169179692512835000; // 128 - bit unsigned for the value
- uint128 balls = 0;
- unsigned long long base = 0;
- unsigned inc = 1000; // initial value of the increaser/decreaser
- while (true) // loop forever
- {
- balls = base*(base+1)*(base+2) / 6; // the formula
- std::cout << '\r' << base; // print the base every loop
- if (balls > wanted_result) // if result is larger than wanted result
- {
- if (inc != 1) inc /= 10; // decrease the incrementer if it's not 1
- base -= inc; // decrease base with incrementer
- }
- else if (balls < wanted_result) // result is smaller that w.result
- base += inc; // increase base
- else // if it is equal
- break;
- }
- std::cout << "\rThe base for a pyramid with 169179692512835000 balls is...\n" << base << "!\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement