HDOJ2009(预处理)

来源:互联网 发布:java与xml 第3版 pdf 编辑:程序博客网 时间:2024/06/17 22:43
#include <iostream> 
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <math.h>


using namespace std;


int a[1001] = { 0 };
int b[3] = { 0 };


void sxh()
{
for (int i = 120; i < 999; i++)
{
int now = i;
int j = 0;
while (now)
{
b[j++] = now % 10;
now /= 10;
}
if (pow(b[0], 3) + pow(b[1], 3) + pow(b[2], 3) == i) a[i] = 1;
}
}


int main()
{
sxh();
int n, m;
while (cin >> n >> m)
{
int no = 0;
for (int i = n; i <= m; i++)
{
if (a[i] )
{
if (no) cout << " ";
cout << i;
no = 1;
}
}
if (!no) cout << "no";
cout << endl;
}
}
原创粉丝点击