1. Erste Version: C, Evgeni Pavlidis


/**
* ACM programming Contest WS 08/09
* UVa Status: accepted
* Run Time: 0.480
* @author Evgeni Pavlidis evgenipavlidis@yahoo.de
*/
#include <stdio.h>
#include <math.h>
#include <string.h>

long long numbers[10000000];
#define MAX 2000000000
#define MAX_EXPONENT 20

int main()
{
int n = 1;

generateHumbleNumbers();


while(1)
{
scanf("%d\n", &n);
if(n == 0)
return 0;

char postfix[5];
strcpy(postfix, "th");


if(n % 100 > 14 || n%100 < 10)
switch(n%10)
{
case 1:
strcpy(postfix, "st");
break;
case 2:
strcpy(postfix, "nd");
break;
case 3:
strcpy(postfix, "rd");
break;
default:
strcpy(postfix, "th");
}


printf("The %d%s humble number is %d.\n", n , postfix, numbers[n]);
}
}

int generateHumbleNumbers()
{
int counter = 0;
int e7,e5,e3,e2;
long long n ;
int max = MAX_EXPONENT;
for(e7 =0; e7 < max; e7++)
for(e5 =0; e5 < max + 5; e5++)
for(e3 =0; e3 < max + 10; e3++)
for(e2 =0; e2 < max + 15; e2++)
{
n = pow(7,e7)*pow(5,e5)*pow(3,e3)*pow(2,e2);
if(n > 0.0)
numbers[counter++] = n;
}

quickSort(0, counter);
}

int quickSort(int l, int r)
{
int i,j;
long long x,tmp;
i = l-1;
x = numbers[r];


for(j = l; j <= r; j++)
if( numbers[j] <= x)
{
i++;
tmp = numbers[i];
numbers[i] = numbers[j];
numbers[j] = tmp;
}

if( i==r )
i--;

if(l < i)
quickSort(l,i);

if((i+1) < r)
quickSort(i+1,r);

}