1 2 3 4 5 6 7 8 9 10 11 12
#include <math.h> #include <iostream.h> using namespace std; int main() { for (int i = 1; i <= 1000; i++) { if (abs(pow(i, 0.5) - (int)pow(i, 0.5)) < 0.001 || abs(pow(i, 1/3.0) - (int)pow(i, 1/3.0)) < 0.001) cout << i << endl; } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
1 4 8 9 16 25 27 36 49 64 81 100 121 144 169 196 225 256 289 324 361 400 441 484 529 576 625 676 729 784 841 900 961