|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <iostream>
#include <algorithm>
using namespace std;
long int min3(long int x,long int y,long int z)
{
return min(min(x, y), z);
}
int main()
{
int a[1505] = { 1 };
a[0] = 1;
int t2 = 0;
int t3 = 0;
int t5 = 0;
for (int i = 1; i < 1500; i++)
{
if (a[t2] * 2 == a[i - 1])
{
t2++;
}
if (a[t3] * 3 == a[i - 1])
{
t3++;
}
if (a[t5] * 5 == a[i - 1])
{
t5++;
}
a[i] = min(a[t2] * 2, a[t3] * 3, a[t5] * 5);
}
cout << "The 1500'th ugly number is " << a[1499] << endl;
return 0;
} |
|