E - Perfect Number
Problem description
We consider a positive integer perfect, if and only if the sum of its digits is exactly 10. Given a positive integer k, your task is to find the k-th smallest perfect positive integer.
Input
A single line with a positive integer k (1 ≤ k ≤ 10 000).
Output
A single number, denoting the k-th smallest perfect integer.
Examples
Input
1
Output
19
Input
2
Output
28
Note
The first perfect integer is 19 and the second one is 28.
解题思路:题目的意思就是找出升序序列(每个数的每位数字总和都为10)中第k个数。暴力水过!
AC代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,k=,tmp,sum,obj[];bool flag;
for(int i=;k<;++i){
tmp=i;sum=;flag=false;
while(!flag && tmp){
if(sum>=)flag=true;//如果sum超过10就无需再比较下去了,因为此时的i一定不满足要求
sum+=tmp%;
tmp/=;
}
if(!flag && sum==)obj[k++]=i;
}
cin>>n;
cout<<obj[n-]<<endl;
return ;
}
E - Perfect Number的更多相关文章
- 507. Perfect Number
We define the Perfect Number is a positive integer that is equal to the sum of all its positive divi ...
- [LeetCode] Perfect Number 完美数字
We define the Perfect Number is a positive integer that is equal to the sum of all its positive divi ...
- [Swift]LeetCode507. 完美数 | Perfect Number
We define the Perfect Number is a positive integer that is equal to the sum of all its positive divi ...
- LeetCode算法题-Perfect Number(Java实现)
这是悦乐书的第249次更新,第262篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第116题(顺位题号是507).我们定义Perfect Number是一个正整数,它等于 ...
- 507. Perfect Number 因数求和
[抄题]: We define the Perfect Number is a positive integer that is equal to the sum of all its positiv ...
- LeetCode Perfect Number
原题链接在这里:https://leetcode.com/problems/perfect-number/#/description 题目: We define the Perfect Number ...
- Codeforces Round #460 (Div. 2)-B. Perfect Number
B. Perfect Number time limit per test2 seconds memory limit per test256 megabytes Problem Descriptio ...
- Codeforces 919 B. Perfect Number
B. Perfect Number time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- [LeetCode] 507. Perfect Number 完美数字
We define the Perfect Number is a positive integer that is equal to the sum of all its positive divi ...
- 【leetcode】507. Perfect Number
problem 507. Perfect Number solution: /* class Solution { public: bool checkPerfectNumber(int num) { ...
随机推荐
- Java中Math对象的属性与方法
Math.sqrt() ——————>计算平方根Math.cbrt()————————>计算立方根Math.pow(a, b)——————————>计算a的b次方Math.max( ...
- 【源码阅读】opencv中opencl版本的dft函数的实现细节
1.函数声明 opencv-3.4.3\modules\core\include\opencv2\core.hpp:2157 CV_EXPORTS_W void dft(InputArray src, ...
- BFS入门篇——RQNOJ195&&335
PID195 / 校园迷宫☆ 从x,y走到去q,w的最小步数,限制是有的点可走,有的点不可走,BFS嘛. #include<bits/stdc++.h> using namespace s ...
- char如何储存3个字节或者4个字节
1.char字符存储的是Unicode编码的代码点,也就是存储的是U+FF00这样的数值,然而我们在调试或者输出到输出流的时候,是JVM或者开发工具按照代码点对应的编码字符输出的. 2. 所以虽然UT ...
- Ubuntu网卡设置:配置/etc/netplan
对于Ubuntu1804版本,经过测试如下配置可以设置静态IP地址: Google@ubuntu:~$ cat /etc/netplan/01-netcfg.yaml network: etherne ...
- 取代PHP原生函数的一些扩展包
前言 虽然程序员无时无刻都在造轮子,但造轮子也有效率之分,用好轮子才能造出好"
- TensorFlow 学习笔记(2)----placeholder的使用
此系列将会每日持续更新,欢迎关注 在TensorFlow中输入值的方式是通过placeholder来实现 例如:做两个数的乘法时,是先准备好两个place, 再将输出值定义成两数的乘法 最后利用ses ...
- Python-程序的控制结构
程序的分支结构 >单分支结构 根据判断条件结果而选择不同向前路径的运行方式 if <条件>: <语句块> 代码示例: guess = eval(input()) if g ...
- 【codeforces 785E】Anton and Permutation
[题目链接]:http://codeforces.com/problemset/problem/785/E [题意] 给你一个初始序列1..n顺序 然后每次让你交换任意两个位置上面的数字; 让你实时输 ...
- Python 1 初识python
1.Python介绍 Python是一种高级语言,与JAVA C# 等同.可以编写各种应用程序,每种语言都有其合适的应用场景.而Python 的优势在于更加人性化.简便的语法规则,以及针对各种具体场景 ...