HDU1406

题目链接

传送门

解题思路

暴力枚举·····不过注意题中没给a和b的大小,所以要保证a < b,输入之后如果a > b则做交换

参考代码

#include <functional>  
#include <algorithm>  
#include <iostream>  
#include <fstream>  
#include <sstream>  
#include <iomanip>  
#include <numeric>  
#include <cstring>  
#include <climits>  
#include <cassert>  
#include <complex>  
#include <cstdio>  
#include <string>  
#include <vector>  
#include <bitset>  
#include <queue>  
#include <stack>  
#include <cmath>  
#include <ctime>  
#include <list>  
#include <set>  
#include <map>  

using namespace std;  

typedef long long LL;  
typedef double DB;  
typedef unsigned uint;  
typedef unsigned long long uLL;  

/** Constant List .. **/ //{  

const int MOD = int(1e9)+7;  
const int INF = 0x3f3f3f3f;  
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;  
const DB EPS = 1e-9;  
const DB OO = 1e20;  
const DB PI = acos(-1.0); //M_PI;  

bool check(int key)  
{  
    int sum = 1;  
    for(int i = 2 ; i < key ; i ++)  
    {  
        if(key % i == 0)  
            sum += i;  
    }  
    if(sum == key)  
        return true;  
    else  
        return false;  
}  

int main()  
{  
    #ifdef ZH  
    freopen("in.txt","r",stdin);  
    #endif  
    int T;  
    scanf("%d",&T);  
    while(T--)  
    {  
        int a , b;  
        scanf("%d%d",&a,&b);  
        int t;  
        if(a > b)  
        {  
            t = a;  
            a = b;  
            b = t;  
        }  
        int cnt = 0;  
        for(int i = a ; i <= b ; i ++)  
        {  
            if(check(i))  
                cnt ++;  
        }  
        printf("%d\n",cnt);  
    }  
}  

暂无评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注

© 2018-2019 惜春令 京ICP备18010644号 网站地图