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