18005 It is not ugly number
2016-07-01 17:42
239 查看
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
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string.h> #include <algorithm> #include <queue> #include <stack> #include <vector>using namespace std;
int a[1500];
typedef pair<int,int> temp;
int main()
{
int t,n,i,cnt=0;
priority_queue<temp,vector<temp>,greater<temp> > pq;
temp tempp;
pq.push(temp(1,2));
for(i=0;i<1205;++i){
tempp=pq.top();
switch(tempp.second){
case 2:pq.push(temp(tempp.first*2,2));
case 3:pq.push(temp(tempp.first*3,3));
case 5:pq.push(temp(tempp.first*5,5));
}
a[i]=tempp.first;
pq.pop();
}
scanf("%d",&t);
while(t--){
scanf("%d",&n);
cnt=0;
i=0;
while(cnt<n){
cnt+=a[i+1]-a[i++]-1;
}
i--;
cnt-=a[i+1]-a[i]-1;
printf("%d\n",a[i]+n-cnt);
}
return 0;
}
相关文章推荐
- 【CF 应用开发大赛】IT Share(IT分享网)
- IT职场英语,必须学会
- 书评:《算法之美( Algorithms to Live By )》
- 动易2006序列号破解算法公布
- it人员要看饮食保健养生谚语
- C#递归算法之分而治之策略
- Ruby实现的矩阵连乘算法
- C#插入法排序算法实例分析
- C#算法之大牛生小牛的问题高效解决方法
- C#算法函数:获取一个字符串中的最大长度的数字
- 超大数据量存储常用数据库分表分库算法总结
- C#数据结构与算法揭秘二
- C#冒泡法排序算法实例分析
- 算法练习之从String.indexOf的模拟实现开始
- C#算法之关于大牛生小牛的问题
- C#实现的算24点游戏算法实例分析
- 经典排序算法之冒泡排序(Bubble sort)代码
- c语言实现的带通配符匹配算法
- 浅析STL中的常用算法
- 算法之排列算法与组合算法详解