Created
January 29, 2014 00:57
-
-
Save KT-Yeh/8679699 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <algorithm> | |
using namespace std; | |
int main() | |
{ | |
unsigned long long int N[1501]; | |
N[1]=1; | |
int p2=1,p3=1,p5=1; | |
for (int n=2; n<=1500; n++){ | |
while (N[p2]*2 <= N[n-1]) p2++; | |
while (N[p3]*3 <= N[n-1]) p3++; | |
while (N[p5]*5 <= N[n-1]) p5++; | |
N[n] = min (N[p2]*2, min (N[p3]*3, N[p5]*5)); | |
} | |
printf("The 1500'th ugly number is %llu.\n",N[1500]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment