C语言算法 丑陋的数

[复制链接]
查看11 | 回复1 | 2010-6-8 17:54:29 | 显示全部楼层 |阅读模式
丑陋的数
Time Limit:1000MSMemory Limit:65536K
Total Submit:51 Accepted:19
Description
丑陋的数是一种它的因数只由2,3,5构成的数。
1,2,3,4,5,6,8,9,10,12是前十个丑陋的数(如:6=2*3是丑陋的数,11=1*11不是丑陋的数),请注意1也算丑陋的数。
给定一个整数N,写一个程序找出第N个丑陋的数。
Input
每行为一个正整数N ( N < 1500 )。
输入数据以N = 0作为结束符。
Output
每行输入数据对应一行输出数据,输出第N个丑陋的数。
输入数据N = 0不要处理。
Sample Input
1
2
9
0
Sample Output
1
2
10

回复

使用道具 举报

千问 | 2010-6-8 17:54:29 | 显示全部楼层
#include using namespace std;int h[5850];int n;void Init(){ int i; int i1,i2,i3; int t1,t2,t3; h[1] = 1; i1=i2=i3=1; for(i=2;i<=5850;i++) {t1 = h[i1]*2; t2 = h[i2]*3;t3 = h[i3]*5; h=min(t1,min(t2,t3));if(h==t1) i1++;if(h==t2) i2++;if(h==t3) i3++; }
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行