18005 It is not ugly number
2017-06-07 20:12
344 查看
18005 It is not ugly number
时间限制:2000MS 内存限制:65535K
提交次数:0 通过次数:0
题型: 编程题 语言: G++;GCC
Description
Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence1, 2, 3, 4, 5, 6, 8, 9, 10, 12, …shows the
first 10 ugly numbers. By convention, 1 is included. Then, here are the first 10 Not ugly numbers:7, 11, 13, 14, 17, 19,
21, 22, 23, 26. Given the integer n, write a program to find and print the n’th Not ugly number.
输入格式
First line is T(T<=10000), the number of cases.
The T lines following. Each line of the input contains a positive integer n (n <= 100000000).
输出格式
For each case, output the n’th Not ugly number .
输入样例
3
1
2
9
输出样例
7
11
23
时间限制:2000MS 内存限制:65535K
提交次数:0 通过次数:0
题型: 编程题 语言: G++;GCC
Description
Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence1, 2, 3, 4, 5, 6, 8, 9, 10, 12, …shows the
first 10 ugly numbers. By convention, 1 is included. Then, here are the first 10 Not ugly numbers:7, 11, 13, 14, 17, 19,
21, 22, 23, 26. Given the integer n, write a program to find and print the n’th Not ugly number.
输入格式
First line is T(T<=10000), the number of cases.
The T lines following. Each line of the input contains a positive integer n (n <= 100000000).
输出格式
For each case, output the n’th Not ugly number .
输入样例
3
1
2
9
输出样例
7
11
23
#include <iostream> #include <cstdio> #include <cstdlib> using namespace std; int min3(int a,int b,int c) { int min=a>b?b:a; return min>c?c:min; } int main() { int min,*p,i,j,f2=0,f3=0,f5=0,n=1500,count; p=(int *)malloc(n*sizeof(int )); *p=1; for(i=1;i<n;i++) { min=min3(*(p+f2)*2,*(p+f3)*3,*(p+f5)*5); p[i]=min; if(min==*(p+f2)*2) f2++; if(min==*(p+f3)*3) f3++; if(min==*(p+f5)*5) f5++; } cin>>j; while(j--) { scanf("%d",&n); i=-1,count=0; while(i++,1) { count+=p[i+1]-p[i]-1; if(count>=n) break; } printf("%d\n",p[i+1]+n-count-1); } }
相关文章推荐
- 18005 It is not ugly number
- 18005 It is not ugly number
- 18005 It is not ugly number
- CvMat执行CvReshape()报错“The matrix is not continuous, thus its number of rows can not be changed”
- 【OpenCV学习笔记】【异常处理】一(The Matrix is not continuous, thus its number of rows can not be changed)
- The project was not built since its build path is incomplete. Can not find
- The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build pat
- Assembly ‘X’ could not be uninstalled because it is required by another application
- The selected server is enabled, but is not configured properly. Deployment to it will not be permitt
- 'ddlCities' has a SelectedValue which is invalid because it does not exist in the list of items
- 【Phpadmin】解决phpadmin的“It is not safe to rely on the system’s timezone settings”问题
- HDU 4627 There are many unsolvable problem in the world.It could be about one or about zero.But this time it is about bigger number.
- 解决php的“It is not safe to rely on the system’s timezone settings”问题
- Axis2,反序列化抛出异常simpleDeserializer encountered a child element , which is not expected,in something it
- The project was not built since its build path is
- MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk.
- 使用date函数出现 It is not safe to rely on the system's time
- date(): It is not safe to rely on the system’s timezone settings.
- "Firefox is already running but is not responding" error message - How to fix it
- Redis提示(error) MISCONF Redis is configured to save RDB snapshots, but it is currently not able to pe