HDU 12,157 XI Festival (sum of approximate)

Source: Internet
Author: User

Tanabata FestivalTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 39837 Accepted Submission (s): 12523


Problem Description Tanabata day, matchmaker came to the digital kingdom, he posted a sign on the city gate, and the people of the Digital Kingdom said: "You want to know who your other half is?" then follow the signs on the way to find it!
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 factor of 12 having 1,2,3,4,6.
Do you want to know your other half?

The first line of input data is a number T (1<=t<=500000), which indicates the number of groups of test data. Then there is 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, export a number that represents the other half of the input data N.

Sample Input
321020

Sample Output
1822

Authorignatius.l
SOURCE Hangzhou Electric ACM Provincial Training Team Qualifying match
original title link: http://acm.hdu.edu.cn/showproblem.php?pid=1215Ideas:from 1 to square root N enumeration, if its approximate, then add, the other one if legal, also addNote that it does not add itself. If squared, the square root n is only added once, see Code 1Method 2 is to make a table, see Code 2AC Code 1:
#include <iostream>using namespace Std;int main () {    int t;    cin>>t;    while (t--)    {        int n,sum=0;        cin>>n;        for (int i=1;i*i<=n;i++)        {            if (n%i==0)            {                sum+=i;                if (i!=1&&i!=n/i)//1 is added once, the square root n is also only added once                    sum+=n/i;            }        }        cout<<sum<<endl;    }    return 0;}

AC Code 2
#include <iostream>using namespace std; #define MAXN 500005int A[maxn];int Main () {for    (int i=1;i<maxn;i++ ) for        (int j=i+i;j<maxn;j+=i)            a[j]+=i;    int t,n;    cin>>t;    while (t--)    {        cin>>n;        cout<<a[n]<<endl;    }    return 0;}



HDU 12,157 XI Festival (sum of approximate)

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.