ACM程序设计题目 Problem U-21
2017-03-12 18:24
225 查看
该题目就是查找3和5的倍数。
找到3和5的最小公倍数,最小公倍数15之内共有七个符合条件的数,用n/7求有多少个15,n%7求是第几个数,输出即可。
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的最小公倍数,最小公倍数15之内共有七个符合条件的数,用n/7求有多少个15,n%7求是第几个数,输出即可。
#include <bits/stdc++.h> using namespace std; int main(){ int i,n,x,y; int a[7]={3,5,6,9,10,12,15}; while(cin>>n){ x=n%7; y=n/7; if(x==0) cout<<15*y<<endl; else cout<<15*y+a[x-1]<<endl; } return 0; }
由于想到晒素数那个例子,想到了预处理这一步,不知道我这算不算预处理。
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
相关文章推荐
- acm程序设计书中题目第s题解析
- ACM程序设计 书中题目N(翻转数字)
- ACM程序设计书中题目V
- ACM程序设计 书中题目Y
- ACM程序设计书中的题目练习后感
- ACM 程序设计竞赛 数学题目
- ACM程序设计书中题目--J(大写字母的更替)
- ACM程序设计书中题目L
- ACM程序设计 书中题目L
- ACM程序设计 书中题目U(美丽的数字)
- ACM程序设计 书中题目Z
- ACM程序设计书中题目--L(字符逆序输出)
- 关于acm程序设计书中题目 #B第二题
- acm程序设计书中题目第e题解析
- ACM程序设计书中题目--E(DNA sorting)
- ACM程序设计书中题目B
- 关于acm程序设计书中题目 #J #K #L
- ACM程序设计书中题目--N(数字反转)
- 关于acm程序设计书中题目 #H 第8题
- ACM程序设计书中题目--M(寻找两倍关系)