《ACM程序设计》书中题目 U
来源:互联网 发布:windows agent 安装 编辑:程序博客网 时间:2024/05/17 18:19
Description
Mike is very lucky, as he has two beautiful numbers, 3 and 5. But he is so greedy that he wants infinite beautiful numbers. So he declares that any positive number which is dividable by 3 or 5 is beautiful number. Given you an integer N (1 <= N <= 100000), could you please tell mike the Nth beautiful number?
Input
The input consists of one or more test cases. For each test case, there is a single line containing an integer N.
Output
For each test case in the input, output the result on a line by itself.
Sample Input
1
2
3
4
Sample Output
3
5
6
9
这道题的基本题意为被3或5整除的数称为美丽数字,要求输出第N个美丽数字。
基本思路为先把所有的美丽数字求出来储存在一个数组中,然后输出对应次序的美丽数字。
源代码如下:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[100001],i,j,n=1,k;
for(i=1;;++i)
{ if(i%3==0||i%5==0)
{ a[n]=i;
++n;
}
if(n>100000)break;
}
while(cin>>k)
{ cout<<a[k]<<endl;
}
}
- 《ACM程序设计》书中题目--problem u
- 《ACM程序设计》书中题目 U
- 《ACM程序设计》书中题目―U
- 《ACM程序设计》书中题目U
- 《ACM程序设计》书中题目 U
- 《acm程序设计》书中题目U-21
- 《ACM程序设计》书中题目 U
- ACM程序设计 书中题目U(美丽的数字)
- 《ACM程序设计》书中题目U(美丽数字)
- acm程序设计书中的题目u
- 《ACM书中题目》 U
- 《ACM程序设计》书中题目
- ACM程序设计书上题目U
- ACM程序设计书中题目--U(寻找第n个能被3或5整除的数)
- 《ACM程序设计》书中题目U 第二十一题 漂亮的数字
- acm书中题目 u-21
- 《ACM程序设计》书中题目--problem j
- 《ACM程序设计》书中题目 J
- windbg高级条件断点初探
- 1051. Pop Sequence
- 51Nod-1128-正整数分组 V2
- vue2+express+mysql小练习
- Tensorflow一些常用基本概念与函数1
- 《ACM程序设计》书中题目 U
- 特征检测和描述(SURF)
- VB键盘输入、常量定义与输出文字和参数
- java实现二叉平衡树
- linux 下redis 安装,python 链接测试
- c++bug小结(一)
- 使用wsimport命令生成webService客户端代码实例
- 【操作系统】信号量与P、V操作
- MySQL 基本操作和用户管理