lltobe 发表于 2013-1-26 12:26:49

练习3.2

// test2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <math.h>
bool getR1(int n);
int main(int argc, char* argv[])
{
 printf("Hello World!\n");
 
 printf("result: %d", getR1(6));
 
 return 0;
}
bool getR1(int n)
{
 int sum=1;
 for(int i=2,l=sqrt(n);i<=l;i++)
 {
  if(0== n%i)
  {
   if(n==i*i)
   {
    sum+=i;
   }
   else
   {
    sum+=i;
    sum+=n/i;
   }
  }
 }
 return sum==n;
}
页: [1]
查看完整版本: 练习3.2