您的位置:首页 > 其它

ACM程序设计题目 Problem U-21

2017-03-12 18:24 225 查看
    该题目就是查找3和5的倍数。

     找到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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: