本站遷移

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

New Website:
http://knightzone.org/

搜尋此網誌

2011年1月21日 星期五

[UVa]10699:Count the factors

直接從2開始到根號N去除除看能不能整除,
能整除就知道其質因數有此數,因此就把質因數個數加一,
接著把N中所有含有的這個質因數除乾淨,再往下一個搜尋。

[C++](0.012)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n;
while( cin >> n && n != 0 )
{
int output = n;
int factor = 0;
int limit = static_cast<int>(sqrt(n));
for( int i = 2 ; i <= limit ; i++ )
if( n % i == 0 )
{
factor++;
while( n % i == 0 ) n /= i;
}
if( n != 1 )
factor++;
cout << output << " : " << factor << endl;
}
return 0;
}

0 意見:

張貼留言