数学-> YY POJ 1338
2013-10-13 22:07
344 查看
Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64uSubmit Status Practice POJ1338DescriptionUgly 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.Given the integer n,write a program to find and print the n'th ugly number.InputEach line of the input contains a postisive integer n (n <= 1500).Input is terminated by a line with n=0.OutputFor each line, output the n’th ugly number .:Don’t deal with the line with n=0.Sample Input
1 2 9 0Sample Output
1 2 10
#include <iostream>using namespace std;int main(){int array[1501] = {1};int a, b, c, n;a = b = c = 0;int temp = 1;for (int i = 1; i < 1501; i++){temp = (2 * array[a] > 3 * array[b] ? 3 * array[b] : 2 * array[a]);temp = (5 * array[c] > temp ? temp : 5 * array[c]);if (temp == 2 * array[a]){a++;}if (temp == 3 * array[b]){b++;}if (temp == 5 * array[c]){c++;}array[i] = temp;}while (cin >> n, n){cout << array[n - 1] << endl;}return 0;}[/code]
相关文章推荐
- 模拟->YY POJ 1028 Web Navigation
- 模拟->YY POJ 2612 Mine Sweeper
- 模拟->YY POJ 2339 Rock, Scissors, Paper
- 模拟->YY POJ 1786
- YY->POJ 1328
- <<数学>>圆角矩形,矩形重叠(一)
- POJ1338 & POJ2545 & POJ2591 & POJ2247 找给定规律的数
- DP <裸> POJ 1157
- poj1061 青蛙的约会 && poj 2115 C Looooops<扩展欧几里得>
- Poj 1338 Ugly Numbers(数学推导)
- POJ 2645 Boastin' Red Socks(组合数学)
- poj 1973 分配任务 进阶动态规划 <难题>
- Box2d源码学习<四>数学库API的实现
- <<数学>>css文字是个不规则图形
- CH BR13数学(啥?-a^b≡a^b mod phi(p)+phi(p)(mod p)(b>=phi(p))公式)
- poj 2553 The Bottom of a Graph 给定图,求其中sinks,即如果可u->v,则一定v->u,那么u就是sinks
- poj 3180 The Cow Prom (Tarjan 求>=2的集团数)
- POJ 3100 & ZOJ 2818 & HDU 2740 Root of the Problem(数学)
- poj2696(mod&nbsp;数学上的定义)
- ACM->poj 2195 Going Home