3 条题解

  • 1
    @ 2021-11-22 20:26:46
    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int N = 100010;
    
    int primes[N], cnt;
    bool st[N];
    
    void get_primes(int m) // 线性筛
    {
        for ( int i = 2; i <= m; i ++ )
        {
            if ( !st[i] ) primes[cnt ++] = i;
            for ( int j = 0; primes[j] <= m / i; j ++ )
            {
                st[primes[j] * i] = 1;
                if ( !( i % primes[j] ) ) break;
            }
        }
    }
    
    int main()
    {
        int n, m; cin >> n >> m;
        get_primes(m);
        int res = 0;
        for ( int i = 0; i < cnt; i ++ )
            if ( primes[i] >= n && primes[i] <= m ) res ++ ;
        cout << res;
        return 0;
    }
    
    
  • 0
    @ 2019-04-20 16:08:17
    a=int(input())
    b=int(input())
    d=0
    
    def prime(x):
        for i in range(2,x):
            if x%i==0:
                return(0)
        return(1) 
        
    for g in range(a,b+1):
        if prime(g)==1 and g>=2:
            d=d+1
    print(d)
    
  • 0
    @ 2019-04-19 15:01:33
    import math
    a=int(input())
    b=int(input())
    cnt=0
    for i in range(a,b+1):
        flag = 1
        if i==1:
            continue
        if (i == 2):
            cnt+=1
        a1 = int(math.ceil(math.sqrt(i)) + 1)
        for j in range(2, a1):
            if i % j == 0:
                flag=0
        if flag:
            cnt+=1
    print(cnt)
    
  • 1

信息

难度
7
分类
(无)
标签
(无)
递交数
638
已通过
121
通过率
19%
被复制
3
上传者