南邮 OJ 1711 丑陋数

丑陋数

时间限制(普通/Java) :  1000 MS/ 3000 MS          运行内存限制 : 65536 KByte
总提交 : 65            测试通过 : 39 

比赛描述

Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 
1, 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. 



输入

Each line of the input contains a postisive integer n (n <= 1500).Input is terminated by a line with n=0.

输出

For each line, output the n’th ugly number .:Don’t deal with the line with n=0.

样例输入

1
2
9
0

样例输出

1
2
10

提示

undefined

题目来源

Lithium




#include<stdio.h>
int main(){
	int a[1501],i,*p2,*p3,*p5;
	a[1] = 1;
	p2 = p3 = p5 = &a[1];
	for(i=2; i<=1500; i++){
		if(*p2*2 <*p3*3)
			a[i] = *p2*2;
		else
			a[i] = *p3*3;
		if(a[i]>*p5*5)
			a[i] = *p5*5;
		while(*p2*2<=a[i])
			p2++;
		while(*p3*3<=a[i])
			p3++;
		while(*p5*5<=a[i])
			p5++;
	}
	while(scanf("%d",&i)==1&&i)
		printf("%d\n",a[i]);
}



你可能感兴趣的:(ACM,南邮OJ,丑陋数)