0


AtCoder Beginner Contest 336 C - Even Digits题解

C - Even Digits Editorial


Time Limit: 2 sec / Memory Limit: 1024 MB

Score: 300300 points

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 (00, 22, 44, 66, and 88).

For example, 00, 6868, and 20242024 are good integers.

You are given an integer �N. Find the �N-th smallest good integer.

Constraints

  • 1≤N≤10^12
  • N is an integer.

Input

The input is given from Standard Input in the following format:

N

Output

Print the N-th smallest good integer.


Sample Input 1Copy

Copy

8

Sample Output 1Copy

Copy

24

The good integers in ascending order are 0,2,4,6,8,20,22,24,26,28,…0,2,4,6,8,20,22,24,26,28,….
The eighth smallest is 2424, which should be printed.


Sample Input 2Copy

Copy

133

Sample Output 2Copy

Copy

2024

Sample Input 3Copy

Copy

31415926535

Sample Output 3Copy

Copy

200662886824422

题解:

要精用vector,防止超时。

#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> a;//类似高精度
int n;
signed main()
{
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
cin >> n;
n-=1;//因为第一位是0嘛
while(n > 0){//25=10进位了
a.push_back(n%5);
n /= 5;
}
if(a.empty()) a.push_back(0);
for(int i = a.size()-1; i > -1; i--)//迭代器,也不算吧,vector也是数组
cout << 2
a[i];
}

标签: c语言 开发语言

本文转载自: https://blog.csdn.net/YC139778/article/details/135609735
版权归原作者 YC139778 所有, 如有侵权,请联系我们删除。

“AtCoder Beginner Contest 336 C - Even Digits题解”的评论:

还没有评论