hdu 1046 完数(水)

http://acm.hdu.edu.cn/showproblem.php?pid=1406

好久不写解题报告了 最近有点颓废 基本不做题 哎 这个题目就是注意所给的两个数的顺序不一定是从小到大的

不说了 粘代码

View Code
 1 //============================================================================
2 // Name : hdu1406.cpp
3 // Author :
4 // Version :
5 // Copyright : Your copyright notice
6 // Description : Hello World in C++, Ansi-style
7 //============================================================================
8
9 #include <iostream>
10 #include<cstdio>
11 #include<cstdlib>
12 using namespace std;
13 bool is_perfect(int m)
14 {
15 int i=0,sum=0;
16 for(i=1;i<m;i++)
17 {
18 if(m%i==0)
19 sum+=i;
20 }
21 if(sum==m)
22 return true;
23 else
24 return false;
25 }
26 int main()
27 {
28 int ncases,begin,end,i,total=0,j,temp;
29 while(scanf("%d",&ncases)!=EOF)
30 {
31 for(i=0;i<ncases;i++)
32 {
33
34 scanf("%d %d",&begin,&end);
35 if(begin>end)
36 {
37 temp=begin;
38 begin=end;
39 end=temp;
40 }
41
42 for(j=begin;j<=end;j++)
43 {
44 if(is_perfect(j)==1)
45 {
46 total++;
47 }
48 }
49 printf("%d\n",total);
50 total=0;
51 }
52 }
53 return 0;
54 }

原文地址:https://www.cnblogs.com/yujiaao/p/2218304.html