HDU-1215-Qixi Festival

Source: Internet
Author: User

Question Link

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

The question should be slightly changed. It is too difficult to think about it. If you have an idea, you can try it to make progress,

At first, I directly sought the factor, sum, and undoubtedly timed out. When is the question so easy? Obviously not,

Flexible. Just a little bit, you can use AC. Everything is in the code.

Code timeout

# Include <stdio. h>
Int main (void)
{
Int t, n, I, J, K, L;
Scanf ("% d", & T );
While (t --)
{
Scanf ("% d", & N );
Int S = 0;
K = n/2;
For (I = 1; I <= K; I ++)
If (N % I = 0)
S = S + I;
Printf ("% d \ n", S );
}
Return 0;
}

 

AC code

# Include <stdio. h>
# Include <math. h>
Int main (void)
{
Int t, n, I, J, K, L;
Scanf ("% d", & T );
While (t --)
{
Scanf ("% d", & N );
If (n = 1)
{
Printf ("0 \ n ");
Continue;
}
K = SQRT (N );
Int S = 0;
For (I = 2; I <= K; I ++)
{
L = N/I;
If (N % I = 0)
{
If (I! = L)
S = S + I + L;
Else
S = S + I;
}
}
Printf ("% d \ n", S + 1 );
}
Return 0;
}

HDU-1215-Qixi Festival

Related Keywords:

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.