1 #include<stdio.h>//月老的烦恼(1)(478) 2 #include<math.h> 3 #include<string.h> 4 #define MAX 500000 5 int a[MAX]; 6 void count() 7 { 8 int i,j,t; 9 t=MAX/2; 10 memset(a,0,sizeof(a)); 11 for(i=1;i!=t;i++){ 12 for(j=i*2;j<=MAX;j+=i){ 13 a[j]++; 14 } 15 } 16 } 17 int main() 18 { 19 int x,n; 20 scanf("%d",&x); 21 count(); 22 while(x--){ 23 scanf("%d",&n); 24 printf("%d\n",a[n]); 25 } 26 return 0; 27 }
本文介绍了一个通过C语言实现的算法,用于计算给定整数范围内所有偶数倍数的数量。该算法首先包含了必要的头文件,接着定义了一个全局整型数组用于存储每个数的倍数计数。核心逻辑在于双重循环,通过遍历数组并增加相应位置的计数来完成任务。最后,通过输入读取和输出显示,验证了算法的有效性。
810

被折叠的 条评论
为什么被折叠?



