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) { ...
随机推荐
- redis数据库学习笔记
redis数据库 工作需要,简单了解一下redis数据库,供后续参考和复习使用. 一.简介 Redis是一个开源(BSD许可),内存存储的数据结构服务器,可用作数据库,高速缓存和消息队列代理.它支持字 ...
- 洛谷——P3833 [SHOI2012]魔法树
P3833 [SHOI2012]魔法树 题目背景 SHOI2012 D2T3 题目描述 Harry Potter 新学了一种魔法:可以让改变树上的果子个数.满心欢喜的他找到了一个巨大的果树,来试验他的 ...
- MySQL(端口3306)
MySQL(二进制)安装: 下载地址:http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.49-linux2.6-x86_64.tar.gz ...
- Asp.NET误人子弟教程:在MVC里面结合JQ实现AJAX
public class Person { public string Name { get; set; } public string City { get; set; } public strin ...
- 第十三节:pandas之groupby()分组
1.Series()对象分组 1.1.单级索引 1.2.多级索引 2.DataFrame()对象分组 3.获取一个分组,遍历分组,filter过滤.
- JDK,JRE,JVM三者关系
已上图,如有疏漏错误请在下面评论区指出,感激不尽!
- C#关键字详解第四节
位 Unicode 字符 char在C#中与C语言不同,他表示的是16位无符号进制的数,在计算机中他是被用来存储字符但是他只能用来存 储一个文字,与string不同string可以存储多个文字或字符, ...
- Awesome Python(中文对照)
python中文资源大全:https://github.com/jobbole/awesome-python-cn A curated list of awesome Python framework ...
- 【学QT】 3 - DEBUG集子
1. [root@localhost helloqt]# make g++ -Wl,-rpath,/usr/local/qt/lib -o cfconv .obj/main.o .obj/cfconv ...
- WeX5 IDE 手机移动开发+JAVA +大数据
http://www.wex5.com/wex5/?qb360=wex501=3534 前端技术 HTML,CSS,JavaScript,EasyUI,Jquery,HTML5,CSS3,Jquery ...