这回结果对了!又超时了!真是愁死我了!
#include <stdio.h>
int main()
{
int s, m, i, j, k;
int sum;
int f(int a,int b);
scanf("%d", &s);
for(i = 1;i <= s;i ++)
{
sum = 0;
scanf("%d", &m);
if(m == 1)
printf("%d %d %d\n", i, m, 3);
else if(m == 2)
printf("%d %d %d\n", i, m, 5);
else if(m == 3)
printf("%d %d %d\n", i, m, 9);
else
{
for(k = 4;k <= m;k ++)
for(j = 2;j <= k - 2;j ++)
if(f(k, j))
sum ++;
sum = (3 + 2*(2*m -3)) + 2*sum;
printf("%d %d %d\n", i, m, sum);
}
}
return 0;
}
int f(int a,int b)
{
int i, c;
c = a > b ? b : a;
for(i = 2;i <= c;i ++)
if(a%i == 0&&b%i == 0)
return 0;
return 1;
}
该学习了。。。