HDU-1286-find new friends

Source: Internet
Author: User

Question Link

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

Questions are messy and should not be,

Started my direct brute force timeout

Timeout code

# Include <stdio. h>

Int main () {int Gy (int x, int y); int C, N, K, I; scanf ("% d", & C); While (c --) {k = 0; scanf ("% d", & N); for (I = 2; I <n; I ++) {If (GY (I, n )) k ++;} printf ("% d \ n", n-k-1);} return 0;} int Gy (int x, int y) {int I; for (I = 2; I <= x; I ++) {If (X % I = 0 & Y % I = 0) return 1 ;} return 0;} the idea is obviously not good at AC code

# Include <stdio. h>
# Include <math. h>
# Include <string. h>
Int main (void)
{
Int N, T, S, I, J;
Int hash [40000];
Scanf ("% d", & T );
While (t --)
{
Memset (hash, 0, sizeof (hash ));
Scanf ("% d", & N );
Int K = n/2;
For (I = 2; I <= k + 1; I ++)
{
If (N % I = 0)
{
For (j = 1; I * j <n; j ++)
Hash [I * j] ++;
}
}
S = 0;
For (I = 2; I <n; I ++)
If (hash [I])
S ++;
Printf ("% d \ n", n-s-1 );
}
Return 0;
}

 

Think about it, think about it, and don't hesitate.

HDU-1286-find new friends

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.