2014年7月6日 星期日

uva 136 Ugly Numbers

把數字有的 2, 3, 5  因數都除掉後,若數字變成 1 ,表示數字的質因數只有 2, 3, 5。

可以用程式把數字算出來後,直接印出即可。算出第 1500 個要花一段時間。

#include <stdio.h>
#include <stdlib.h>

int main(void){
    /*int i,counter=0,has,tmp;

    i=2; counter=1;
    while(1){
        has=0; tmp=i;

        while(tmp%2==0) tmp/=2;
        while(tmp%3==0) tmp/=3;
        while(tmp%5==0) tmp/=5;

        if(tmp==1) ++counter;

        if(counter==1500) break;

        ++i;
    }

    printf("The 1500'th ugly number is %d.\n",i);*/

    printf("The 1500'th ugly number is 859963392.\n");

    return 0;
}

沒有留言:

張貼留言