2 条题解

  • 2
    @ 2023-10-3 14:41:58
    #include<iostream> 
    #include<cmath> 
    #include<cstdio> 
    #include<algorithm> 
    #include<cstring>
    #include<string> 
    using namespace std;
    bool fun(int a){
    	for(int i=2;i<a;i++){
    		if(a%i == 0){
    			return false; 
    		}
    	}
    	return true;	
    }
    int main(){
    	int n;
    	cin >> n;
    	bool b;
    	int cnt=0;
    	for(int i=2;i<=n;i++){
    		b = fun(i);
    		if(b){
    			cnt++;
    		}
    	}
    	cout << cnt;
    	return 0;
    }
    
    • 1
      @ 2024-2-7 11:25:51
      #include <bits/stdc++.h>
      
      using namespace std;
      
      bool cheakPrime(int number) {
          if (number <= 1) {
           	return false;
      	} else {
      	 	for (int i = 2; i < number; i++) {
      	 	    if (number % i == 0) {
      	 	 		return false;
      			}
      		}
      		return true;
      	}
      }
      
      int main() {
      	int n;
      	cin >> n;
      	int counter = 0;
      	for (int i = 2; i <=n; i++) {
      		if (cheakPrime(i)) {
      			counter = counter + 1;
      			
      		}
      	}
      	cout << counter;
      	return 0;
      }
      
      • 1

      信息

      ID
      6939
      时间
      1000ms
      内存
      128MiB
      难度
      1
      标签
      (无)
      递交数
      15
      已通过
      12
      上传者