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){//2*5=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];
    }

  • 12
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值