第二题 #include<iostream> #include <string> using namespace std; //int a, b, c; //cin >> a >> b >> c; //int res; //res = 1 + b - c; //cout << res; //return (0); int array1[1001]; int array2[1001]; int main() {     int n;     cin >> n;     if (n <= 1)     {         cout << 0 << endl;         return 0;     }     for (int i = 0; i < 1001; i++)     {         array1[i] = array2[i] = 0;     }     //int *array1 = new int[n + 1]{0};     /*计算素数*/     //int *array2 = new int[n + 1]{0};     for (int i = 2; i <= n; i++)     {         if (array2[i] == 0)         {             for (int j = 2; j*i <= n;j++)             {                 array2[j*i] = 1;             }         }         if (array2[i] == 1)         {             continue;         }     }     /*方幂*/     for (int i = 2; i <= n; i++)     {         if (array2[i] == 0)         {             array1[i] = 1;             //int j = 1;             int base = i;             int temp = i;             while (1)             {                 temp *= base;                 if (temp > n)                 {                     break;                 }                 else                 {                     array1[temp] = 1;                 }             }         }         else         {             continue;         }     }     int cnt = 0;     for (int i = 2; i <= n; i++)     {         if (array1[i]==1)         {             cnt++;         }     }     //delete[] array1;     //delete[] array2;     return (0); }
点赞 评论

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务