HDU 1215 Qixi Festival (Number Theory: factor and)

Source: Internet
Author: User

Link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1215

 

Scream .. It is really not suitable for the number topic .. Various timeouts, re...

Well, the question is very clear, and how to do it is the same thing.

The limit of 500000 cannot be violent.

In this case, the tables are the most earthy.

 

How to build a table?

First, a factor must include a multiple of a number.

Remember this ..

 

 

ACCode:

 

# Include <iostream> using namespace STD; int A [500001]; void fun () {int I, j; for (I = 1; I <= 500000; I ++) // 1 each person adds a [I] = 1; for (I = 2; I <= 250001; I ++) // just half of it, it is meaningless {for (j = I + I; j <= 500000; j + = I) // as long as the number is a multiple of I, it must contain the I factor, I will not add it myself. From the next part of I, {A [J] + = I; // so I will be added.} int main () {int M, N; fun (); scanf ("% d", & M); While (M --) {scanf ("% d", & N ); printf ("% d \ n", a [n]);} 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.