[問題] 找perfect number
開發平台: (例: VC++ or gcc/g++ or Dev-C++, Windows or Linux)
VC++
有問題的code: (請善用置底文標色功能)
#include "stdafx.h"
#include"iostream"//標頭檔
#include"iomanip"
#include"cmath"
using namespace std;
using std::setw;
using std::fixed;
using std::setprecision;
void PerfectNumber(unsigned long double num,unsigned long double &count);
int _tmain(int argc, _TCHAR* argv[])
{
unsigned long double a,i,j,k,co=0;
cin>>a;
for(i=2;i<=a;i++)
{
PerfectNumber(i,co);
}
cout<<"the total is "<<co<<endl;
system("pause");
return 0;
}
void PerfectNumber(unsigned long double num,unsigned long double &count)
{
unsigned long double i,j,sum=0;
//count=0;
if(num%2==0)
{
for(j=1;j<num-1;j++)
if(num%j==0)
{
sum=sum+j;
}
if(sum==num)
{
cout<<num<<" is a perfect number"<<endl;
count=count+1;
}
}
}
補充說明:
以編譯過但不知要怎找才能找到8589069059
就是可以讓他快一點嗎
以上CODE是過的
謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.7.59
→
11/06 17:20, , 1F
11/06 17:20, 1F
→
11/06 17:29, , 2F
11/06 17:29, 2F
→
11/06 18:05, , 3F
11/06 18:05, 3F
→
11/06 18:27, , 4F
11/06 18:27, 4F
→
11/06 19:11, , 5F
11/06 19:11, 5F
→
11/07 13:03, , 6F
11/07 13:03, 6F
→
11/07 13:04, , 7F
11/07 13:04, 7F