poj 1218(模拟)

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
    int n,p;
    int i,j;
    scanf("%d",&n);
    bool data[101];
    for(i=3;i<=100;i++){
        for(j=i;j<=100;j+=i){
            data[j] = !data[j];
        }
    }
    while(n--){
        int ans = 0;
        scanf("%d",&p);
        memset(data,true,sizeof(data));
        for(i=2;i<=p;i+=2){
            data[i] = !data[i];
        }
        for(i=3;i<=p;i++){
            for(j=i;j<=p;j+=i){
                data[j] = !data[j];
            }
        }
        for(i=1;i<=p;i++){
            if(data[i])ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
} 

 

上一篇:No.272 - LeetCode[861] Score After Flipping Matrix - 贪心


下一篇:4类型转换