HDU 1215. Tanabata Festival "Screening Method" "July 26"

Source: Internet
Author: User

Tanabata Festival

On the day of Tanabata, matchmaker came to the digital Kingdom , where he posted a sign on the city gate and said to the people of the Digital kingdom : " Do you want to know who the other half of you are ? then follow the signs and find out. !"
People come to the notice before they want to know who is their other half . The notice is as follows :



the factor of the number n is all positive integers that are smaller than n and divisible by n , such as the factors are 1,2,3,4,6.
Do you want to know your other half ?

Input

The first line of the input data is a number T (1<=t<=500000), which indicates the number of groups of test data . then the T Group test Data , each set of test data has only one number N (1<=n<=500000).

Output

For each set of test data, output A number that represents the other half of the input data N .

Sample Input

321020

Sample Output

18

22

Obviously, the poor lift is not a drop ~

Similar to the screening method to find the factor and.

#include <iostream> #include <cstdio>using namespace Std;int f[500001]={0};int Main () {for    (int i=1;i <=500000;i++)        f[i]=1;    for (int i=2;i<=250001;i++) {for        (int j=i+i;j<=500000;j+=i)            f[j]+=i;    }    int t,x;    scanf ("%d", &t);    while (t--) {        scanf ("%d", &x);        printf ("%d\n", F[x]);    }    return 0;}

then a little bit of knowledge of the screening method:

Screening Method

Screening method is also called Sieve method, is not more than the natural numberN(N>1) of allPrime NumberOne of the methods. It is said to be the eratosthenes of ancient Greece (Eratosthenes, ca. BC274~194years) invented, also known as Eratosthenes sieve. The specific practice is: firstNa natural number is arranged in order. 1not prime, nor composite, to be crossed. Second number2is the prime number left, and the2all the back can be2The numbers are divided evenly. 2the first number that was not crossed at the back was3, put3stay, and then put3all the back can be3The numbers are divided evenly. 3the first number that was not crossed at the back was5, put5stay, and then put5all the back can be5The numbers are divided evenly. Doing this all the time, it will not exceedNall the composite are sifted away, leaving no more thanNof all prime numbers. Because the Greeks wrote the numbers on the painted plates, each one to be counted, on the top of the small point, after the work of seeking prime numbers, many of these dots are like a sieve, so the Eratosthenes method is called"Eratosthenes Sieve", Short"Sieve Method". (another explanation was that the numbers were written on the paper grass, and each number was to be crossed, the number was dug, and after the work of searching for prime numbers was finished, many of the holes were like a sieve.) )


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

HDU 1215. Tanabata Festival "Screening Method" "July 26"

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.