题解
C - Even Digits
Problem Statement
A non-negative integer n is called a good integer when it satisfies the following condition:
All digits in the decimal notation of n are even numbers (0, 2, 4, 6, and 8).
For example, 0, 68, and 2024 are good integers.You are given an integer N. Find the N-th smallest good integer.
Sample Input 1
8
Sample Output 1
24
Sample Input 2
133
Sample Output 2
2024
Sample Input 3
31415926535
Sample Output 3
2006628868244228
题意:输出第n个好整数(满足每个数字都是偶数的数字)
思路:通过观察数字的变化,可以发现是以5为循环点,由此猜测是五进制转化来
代码区域
#include <iostream>
#include<stack>
using namespace std;
int main()
{
long long x = 0;
cin >> x;
stack<long long>s;
if (x == 1)
{
cout << 0;
return 0;
}
x = x - 1;
while (x)
{
s.push(x % 5);
x /= 5;
}
while (!s.empty())
{
int a = 0;
a = s.top();
cout << a * 2;
s.pop();
}
return 0;
}