本站遷移

因為我最近租用了網路空間以及網域,
故本站已遷移至新網站~
這邊的資訊已經正在進行搬移的工作~
希望各位可以到新網站去逛XD

New Website:
http://knightzone.org/

搜尋此網誌

2011年2月26日 星期六

[Zerojudge]a040: 阿姆斯壯數

先找尋位數,接著再分解各個位數,
然後給它乘個位數次方,
接著加起來看看有沒有跟原來的數一樣,
就可以得解。

[C++](80ms, 714KB)
#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 意見:

張貼留言