1108

题目描述

Paula and Tai are couple. There are many stories between them. The day Paula left by airplane, Tai send one message to telephone 2200284, then, everything is changing… (The story in “the snow queen”).

After a long time, Tai tells Paula, the number 220 and 284 is a couple of friends number, as they are special, all divisors of 220’s sum is 284, and all divisors of 284’s sum is 220. Can you find out there are how many couples of friends number less than 10,000. Then, how about 100,000, 200,000 and so on.

The task for you is to find out there are how many couples of friends number in given closed interval [a,b]

输入

There are several cases.

Each test case contains two positive integers a, b(1<= a <= b <=500,000).

Proceed to the end of file.

输出

For each test case, output the number of couples in the given range. The output of one test case occupied exactly one line.

样例输入

1 100
1 1000

样例输出

0
1

提示


6 is a number whose sum of all divisors is 6. 6 is not a friend number, these number is called Perfect Number.


来源

辽宁省赛2010

打表代码:


#include<stdio.h>
#include<string.h>
int a[5000010];
int main() 
{
    int i,j;
    int c=5000010;
    a[0] = a[1] = 1;
    memset(a,0,sizeof(a));
    for(i = 2; i<=c; i++){
        a[i]++;//每个数都有1这个因子
        for(j = 2*i; j <= c; j += i){
            ans[j] += i;//因为不算本身,所以从2*i开始,+i就是3*i,以此类推,把所有i的倍数加上i这个因子
        }
    }
    int k=0;
    for(i = 2; i <= c; i++){
        if(a[i] <= c && i == a[a[i]] && i < a[i]){//i,a[i]都在500000以内
            printf(" %d , %d , ",i,a[i]);
            k++;
            if(k%4==0)
                puts("\n");
        }
    }
}
实现程序:

   
   
#include <stdio.h> int a[]={220,284,1184,1210,2620,2924,5020,5564,6232,6368,10744,10856,12285,14595,17296,18416, 63020,76084,66928,66992,67095,71145,69615,87633,79750,88730,100485,124155,122265, 139815,122368,123152,141664,153176,142310,168730,171856,176336,176272,180848, 185368,203432,196724,202444,280540,365084,308620,389924,319550,430402,356408, 399592,437456,455344,469028,486178};
int main() {     int c,d,i;     while(~scanf("%d %d",&c,&d))     {         int ans=0;         for(i=0;i<56;i+=2)         {             if(c<=a[i] && a[i+1]<=d)                 ans++;         }         printf("%d\n",ans);     }     return 0; }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值