Posted on 2010-08-13 21:20
MiYu 閱讀(448)
評(píng)論(0) 編輯 收藏 引用 所屬分類:
ACM ( 水題 )
MiYu原創(chuàng), 轉(zhuǎn)帖請(qǐng)注明 : 轉(zhuǎn)載自 ______________白白の屋
題目地址:
http://acm.hdu.edu.cn/showproblem.php?pid=1406
題目描述:
完數(shù)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6817 Accepted Submission(s): 2131
Problem Description
完數(shù)的定義:如果一個(gè)大于1的正整數(shù)的所有因子之和等于它的本身,則稱這個(gè)數(shù)是完數(shù),比如6,28都是完數(shù):6=1+2+3;28=1+2+4+7+14。
本題的任務(wù)是判斷兩個(gè)正整數(shù)之間完數(shù)的個(gè)數(shù)。
Input
輸入數(shù)據(jù)包含多行,第一行是一個(gè)正整數(shù)n,表示測(cè)試實(shí)例的個(gè)數(shù),然后就是n個(gè)測(cè)試實(shí)例,每個(gè)實(shí)例占一行,由兩個(gè)正整數(shù)num1和num2組成,(1<num1,num2<10000) 。
Output
對(duì)于每組測(cè)試數(shù)據(jù),請(qǐng)輸出num1和num2之間(包括num1和num2)存在的完數(shù)個(gè)數(shù)。
Sample Input
2
2 5
5 7
Sample Output
0
1
水題,直接無視;
代碼如下:
#include <iostream>
#include <cmath>
using namespace std;
int judge ( int a, int b )
{
int n = 0;
if ( a > b )
a ^= b ^= a ^= b;
if ( 6 >= a && 6 <= b )
n ++;
if ( 28 >= a && 28 <= b )
n ++;
if ( 496 >= a && 496 <= b )
n ++;
if ( 8128 >= a && 8128 <= b )
n ++;
return n;
}
int main()
{
int T;
scanf ( "%d",&T );
{
while ( T-- )
{
int a,b;
scanf ( "%d%d",&a,&b );
printf("%d\n",judge ( a,b ) );
}
}
return 0;
}