刚开始用了几次gcd(),结果n次tle, 最后用了筛选法,终于a了,效率提高不少啊!
http://acm.hdu.edu.cn/showproblem.php?pid=1286
View Code
#include " iostream "
using namespace std;
int main()
{
int n,a,i,j,count;
int b[ 32768 ];
cin >> n;
while (n -- )
{
cin >> a;
memset(b, 0 , sizeof (b));
for (i = 2 ;i <= a;i ++ )
{
if (a % i == 0 && b[i] == 0 )
{
for (j = i;j <= a;j += i)
{
b[j] = 1 ;
}
}
}
count = 0 ;
for (i = 1 ;i < a;i ++ )
{
if (b[i] == 0 ) count ++ ;
}
cout << count << endl;
}
return 0 ;
}