AtCoder Beginner Contest 336 题解

题解

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;
}
  • 14
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值