zoukankan      html  css  js  c++  java
  • 【luogu P1865 A % B Problem】 题解

    题目链接:https://www.luogu.org/problemnew/show/P1865

    其实就是埃拉托色尼筛素数模板...

    好像每个数暴力枚举到sqrt()也可以...就算当我无聊练手罢

     1 #include <cstdio>
     2 #include <cmath>
     3 #include <algorithm>
     4 #include <cstring>
     5 using namespace std;
     6 const int maxn = 1000000 + 10;
     7 bool prime[maxn];
     8 int n, m, left, right, sq, tot = 0;
     9 int main()
    10 {
    11     memset(prime,0,sizeof(prime));
    12     scanf("%d%d", &n, &m);
    13     
    14     sq = sqrt(m);
    15     prime[1] = 1;
    16     for(int i = 2; i <= sq; i++)
    17         if(prime[i] == 0)
    18         {
    19             for(int j = i*i; j <= m; j+=i)
    20             prime[j] = 1;
    21         }
    22     
    23     for(int i = 1; i <= n; i++)
    24     {
    25         scanf("%d%d", &left, &right);
    26         if(left > m || right > m || left <= 0 || right <= 0) 
    27         {
    28             printf("Crossing the line
    ");
    29             continue;
    30         }
    31         else
    32         {
    33             for(int j = left; j <= right; j++)
    34             {
    35                 if(prime[j] == 0)
    36                 tot++;
    37             }    
    38             printf("%d
    ",tot);
    39             tot = 0;
    40         }
    41     
    42     }
    43     return 0;
    44 }

    隐约雷鸣,阴霾天空,但盼风雨来,能留你在此。

    隐约雷鸣,阴霾天空,即使天无雨,我亦留此地。

  • 相关阅读:
    组合模式
    数据去重
    combiner
    合并文档
    对象锁 区别 类锁
    一个简单的死锁示例
    线程安全的单例模式
    线程安全与不安全(误解)
    tf.nn.max_pool 池化
    tf.nn.depthwise_conv2d 卷积
  • 原文地址:https://www.cnblogs.com/MisakaAzusa/p/8476153.html
Copyright © 2011-2022 走看看