NBUT1223 Friends number (playing table, violence)

Source: Internet
Author: User
Tags time limit cmath

Topic:

[1223] Friends number time limit: Ms Memory limit: 131072 K problem description

Paula and Tai are couple. There is many stories between them. The day Paula-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 and 284 was a couple of friends number, as they is special, all divisor S of 284, and all divisors of 284 ' s sum is 220. Can you find out there is how many couples of friends number less than 10,000. Then, what about 100,000, 200,000 and so on.


The task for-is-find out there-many couples of friends number in given closed interval [a, b].









Enter there is several cases.
Each test case contains positive integers a, B (1<= a <= b <=5,000,000).
Proceed to the end of file. Output the For each test case, output the number of couples in the given range. The output of one test case occupied exactly one line.
Sample input

1
1 1000
Sample output
0
1
Tips
6 is a number whose sum of all divisors is 6. 6 is isn't a friend number, these number is called Perfect number.
Source
Liaoning Province Race 2010
Operation

Ideas:

The test instructions of this question I read for a long time to understand, sure enough or too food.

The topic defines a "friendship number", which is defined as: two number A and all the factors of b,a (not including itself) and all the factors that add up equals b,b (do not contain itself) and add up exactly equal to a, such number is called Friendship number, data volume has 500,000, first table processing, and then solve.

To play the table code:

#include <cstdio>
#include <cstring>
#include <cctype>
#include <string>
# Include <set>
#include <iostream>
#include <stack>
#include <cmath>
# Include <queue>
#include <vector>
#include <algorithm>
#define MEM (A, B) memset (A, B, sizeof (a))
#define INF 0x3f3f3f3f
#define N 5000000+20
#define MOD 10007
#define M 1000000+10
#define LL Long Long
using namespace std;
int num[n];//The sum of its number of factors is how many
int main ()
{
    num[0]=num[1]=1;
    for (int i=2;i<=n;i++)
    {
        num[i]++;
        for (int j=2*i;j<=n;j+=i)
        {
            num[j]+=i;
        }
    }
    for (int a=2;a<=n;a++)
    {
        int b=num[a];//b equals the sum of all the number of factors of a
        if (b<=n&&a==num[b]&&a <B)//b in the range of N, a equals the sum of all the factors of B, a<b
            printf ("%d,%d,", A, b);
    }

    return 0;
}
Problem Solving Code:

#include <cstdio> #include <cstring> #include <cctype> #include <string> #include <set> # Include <iostream> #include <stack> #include <cmath> #include <queue> #include <vector> # Include <algorithm> #define MEM (A, B) memset (A,b,sizeof (a)) #define INF 0x3f3f3f3f #define N 5000000+20 #define MOD 1
0007 #define M 1000000+10 #define LL Long long using namespace std; int a[10000]= {220,284,1184,1210,2620,2924,5020,5564,6232,6368,10744,10856,12285,14595,17296,18416, 63020,76084,6
    6928,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,503056,514736,522405,525915,600392,669688,609928,686072,624184,691256, 635624,712216,643336,652664,667964,783556,726104,796696,802725,863835,879712,901424,898216, 980984,947835,1125765,998104,1043096,1077890,1099390,1154450,1189150,1156870,1292570,1175265,
    1438983,1185376,1286744,1280565,1340235,1328470,1483850,1358595,1486845,1392368,1464592,1466150,
    1747930,1468324,1749212,1511930,1598470,1669910,2062570,1798875,1870245,2082464,2090656,2236570,
    2429030,2652728,2941672,2723792,2874064,2728726,3077354,2739704,2928136,2802416,2947216,2803580,
    3716164,3276856,3721544,3606850,3892670,3786904,4300136,3805264,4006736,4238984,4314616,4246130,
4488910,4259750,4445050};
    int main () {int x, y;
        while (cin>>x>>y) {int sum=0;
        for (int i=0; i<=150; i+=2) {if (a[i]>=x&&a[i+1]<=y) sum++;
    } cout<<sum<<endl;
} return 0;

 }



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.