然後給它乘個位數次方,
接著加起來看看有沒有跟原來的數一樣,
就可以得解。
[C++](80ms, 714KB)
This file contains 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<iostream> | |
#include<cmath> | |
#define ERROR 0.0000001 | |
using namespace std; | |
int main() | |
{ | |
int n, m; | |
while( cin >> n >> m ) | |
{ | |
bool print = 0; | |
for( int i = n ; i <= m ; i++ ) | |
{ | |
int temp = i; | |
int sum = 0; | |
int digit = 0; | |
while( temp ) | |
{ | |
digit++; | |
temp /= 10; | |
} | |
temp = i; | |
while( temp ) | |
{ | |
sum += (int)( pow( (double)(temp%10) , (double)digit ) + ERROR ); | |
temp /= 10; | |
} | |
if( sum == i ) | |
{ | |
if( print ) | |
cout << ' '; | |
print = 1; | |
cout << i; | |
} | |
} | |
if( !print ) | |
cout << "none"; | |
cout << endl; | |
} | |
return 0; | |
} |
0 意見:
張貼留言