Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //http://math.stackexchange.com/questions/1427250/number-of-solutions-in-this-number-puzzle
- #include <cstdio>
- #include <cstdint>
- #include <cinttypes>
- inline bool okay(int64_t num) {
- int counts[10] = {0,0,0,0,0,0,0,0,0,0};
- int64_t temp;
- temp = num;
- for (int i=0;i<10;++i) {
- int digit = temp%10;
- ++counts[digit];
- temp /= 10;
- }
- temp = 0;
- for (int i=0;i<10;++i) {
- temp = temp*10 + counts[i];
- }
- return temp == num;
- }
- int main(int /*argc*/, char* /*argv*/[]) {
- #if 0
- printf("%d\n",okay(6210001000));
- getchar();
- #else
- int64_t num = 0LL;
- int64_t maximum = 9999999999LL;
- while (num <= maximum) {
- if (okay(num)) printf("%" PRId64 "\n",num);
- ++num;
- if (num%10000000LL==0) {
- printf("%.3f%% complete\n",100.0*static_cast<double>(num)/static_cast<double>(maximum));
- }
- }
- getchar();
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement