AtCoder Beginner Contest 336 C Even Digits

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\leq N\leq 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 1

8

Sample Output 1

24

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

Sample Input 2

133

Sample Output 2

2024

Sample Input 3

31415926535

Sample Output 3

2006628868244228

解读题意可知:

当十进制表示的各位数中仅包含(0,2,4,6,8)的数成为良好整数。

给一个数字n,求第n个良好整数。

解法:

使用5进制即可。

代码展示:

#include<bits/stdc++.h>
using namespace std;
#define int long long//宏定义,题目数据过大防止背爆掉。经手搓代码最大不超过1e18可以用long long
signed main()
{
    int n;
    cin>>n;
    n--;//先让n自减一
    int ans=0;
    for(int i=1;n!=0;i*=10)//i每次循环都乘10表示当前位数
    {
        int a=n%5;//定义一个整数a来判断当前位数应该为几
        ans=ans+i*2*a;
        n/=5;//每次循环让n整除5,也就是5进制。
    }
    cout<<ans;
    return 0;
}

以上纯自我想法 如有错误可以告诉我。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值