HDU 1999 Non-touch number (number N of the Sieve method to find the sum of the true factors) __ACM

Source: Internet
Author: User
Topic address
The main idea: S (n) is the sum of the true factors of n of positive integers, a factor that is less than n and divisible by n, such as S (12) =1+2+3+4+6=16. If any number m,s (m) is not equal to N, then it is said that N is a non-touch number, and that the number within 1000 is not a number.
To solve the problem: to determine whether a number n is not a number, we must determine whether there is not a positive integer m of the sum of the true factor, it will be within 1000 of the sum of the true factor to find the sum of the true factor and the Sieve method
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <queue>
#include <string>


using namespace std;


const int MAXN = 1000000+10;
const int MAXM = 1000+10;


int SUM[MAXN],SIGN[MAXM];


int main ()
{
    memset (sum,0,sizeof (sum));
    memset (sign,0,sizeof (sign));
    for (int i = 1; I <= 500000; i++)/sieve method to find S (n) and save it with sum of the array
    {for
        (int j = 2*i; J <= 1000000; j = i)
        {
            SUM[J] + = i
        }
    }
    for (int i = 1; I <= 1000000 i++)//1000 of S (m)
        if (Sum[i] < 1000)
            sign[sum[i] = 1;
    int t,n;
    scanf ("%d", &t);
    while (t--)
    {
        scanf ("%d", &n);
        if (!sign[n])
            puts ("yes");
        Else
            puts ("no");
    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.