HDU 1406. Number of "screening methods and Special Methods" "July 27"

Source: Internet
Author: User

Finish number

It seems that my heart is not thin enough ah, this for a acmer, too deadly! Problem description Definition: If a positive integer greater than 1 equals the sum of all the factors equal to its own, then the number is said to be the number, such as 6, 28 is the completion of the number: 6=1+2+3;28=1+2+4+7+14.

The task is to determine the number of two positive integers.

Input data contains multiple lines, the first line is a positive integer n, which indicates the number of test instances, then n test instances, each of which consists of two positive integers num1 and num2, (1<num1,num2<10000).

Output for each set of test data, print out the number of NUM1 and num2 (including NUM1 and num2) that exist.

Sample Input
22 55 7

Sample Output
01
this question, at first glance simple! I wa 8 times!!!! First of all, according to the completion of the definition, you can calculate at the time of input, the same can be followed by the previous blog mentioned in the filter method, the input before the calculation, input directly after the judgment. There is also a detail, NUM1 and num2 size not necessarily!!! This is the pit! The code is as follows:

#include <cstdio> #include <iostream>using namespace Std;int f[10010];int Main () {for    (int i=0;i< 10010;i++)        f[i]=1;    for (int i=2;i<5005;i++) for    (int j=i+i;j<10010;j+=i)        f[j]+=i;    int n,num1,num2;    while (scanf ("%d", &n)!=eof&&n)        while (n--) {            int sum=0;            scanf ("%d%d", &num1,&num2);            int minn=num1<num2?num1:num2;            int maxn=num2>num1?num2:num1;            for (int i=minn;i<=maxn;i++)                if (f[i]==i) sum++;            printf ("%d\n", sum);        }    return 0;}

by calculation, however, it is known that the number of 6,28,496,8128!!!!!! within 10000 will be: OK, direct judgment ... Just Judge 4 times ... The code is as follows:

#include <cstdio> #include <iostream>using namespace Std;int f[4]={6,28,496,8128};int main () {    int n, num1,num2;    while (scanf ("%d", &n)!=eof&&n)        while (n--) {            int sum=0;            scanf ("%d%d", &num1,&num2);            int minn=num1<num2?num1:num2;            int maxn=num2>num1?num2:num1;            for (int i=0;i<=4;i++)                if (F[I]>=MINN&&F[I]<=MAXN) sum++;            printf ("%d\n", sum);        }    return 0;}

there is a little trick, in the above code is useless: If you want to exchange two number of values:

int a=1,b=2;a^=b^=a^=b;//The value of the interchange, A, B. It is said that this is the shortest code ~ ~ Is it true?





Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 1406. "Filter method and Special method" "July 27"

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.