Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <assert.h>
- #include <inttypes.h>
- #include <vector>
- typedef unsigned int uint_t;
- const uint_t D = 10;
- class Solver {
- void do_solve(std::vector<uint8_t> &v, uint64_t sum, uint64_t prod, uint64_t n, uint8_t d)
- {
- uint_t l = v.size();
- for (uint8_t j = d; j >= 2; j--) {
- v.push_back(j);
- uint64_t sumj = sum + j;
- uint64_t prodj = prod * j;
- uint64_t nj = (prodj - sumj) + l + 1;
- if (nj == n) {
- printf("%" PRIu64 ": ", n);
- for (uint8_t x: v)
- printf("%u ", (uint_t) x);
- printf("\n");
- }
- if (nj <= n)
- do_solve(v, sumj, prodj, n, j);
- v.pop_back();
- }
- }
- public:
- void solve(uint64_t n)
- {
- std::vector<uint8_t> v;
- do_solve(v, 0, 1, n, D - 1);
- }
- };
- int main()
- {
- Solver s;
- s.solve(5);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement