首页 > 其他分享 >P1865 A % B Problem

P1865 A % B Problem

时间:2024-04-07 13:12:06浏览次数:29  
标签:P1865 int 题解 long && Problem

原题链接

题解

1.筛一筛就行

code

#include<bits/stdc++.h>
using namespace std;
int heshu[1000006]={0},f[1000007]={0};
int main()
{
    int n,m;
    cin>>n>>m;
    for(long long i=2;i<=m;i++)
    {
        if(!heshu[i]) for(long long k=i*i;k<=m;k+=i) heshu[k]=1;
    }

    for(int i=2;i<=m;i++) f[i]=f[i-1]+!heshu[i];
    while(n--)
    {
        int l,r;
        cin>>l>>r;
        if(l>=1&&r>=1&&l<=m&&r<=m&&l<=r) cout<<f[r]-f[l-1]<<endl;
        else puts("Crossing the line");
    }
    return 0;
}

标签:P1865,int,题解,long,&&,Problem
From: https://www.cnblogs.com/pure4knowledge/p/18118846

相关文章

  • Randomness Is All You Need: Semantic Traversal of Problem-Solution Spaces with L
    本文是LLM系列文章,针对《RandomnessIsAllYouNeed:SemanticTraversalofProblem-SolutionSpaceswithLargeLanguageModels》的翻译。随机性就是你所需要的:具有大型语言模型的问题解决空间的语义遍历摘要1引言2相关工作3模型4算法5评估6实现7结论摘......
  • CF30D King's Problem? 题解
    CF30D题意有\(n+1\)个点,其中的\(n\)个点在数轴上。求以点\(k\)为起点走过所有点的最短距离,允许重复。思路有两种情况:\(k\)在数轴上(如图1)。\(k\)在第\(n+1\)个点上(如图2)。图1:图2:像第一种情况:一定存在数轴上某点\(k\),使得人先走遍\(1\simk\),回来,再走遍......
  • CF1934B Yet Another Coin Problem 题解
    CF1934BYetAnotherCoinProblem题解题意目前有\(5\)种硬币,面值分别为\(1,3,6,10,15\)。给你一个数字\(n\),求出可以凑出\(n\)的最少的硬币的数量。思路这道题,大多数的人大概会想到动态规划的方法。但是,我们应该有敢于创新的精神。于是我就想到了一个简单的数学方法......
  • 【2021.6.26 NOI模拟】Problem B. 简单题 another solution
    ProblemDescriptionInput从文件b.in中读入数据。一个正整数n。Output输出到文件b.out中。一个整数表示答案。SampleDataInput#1Copy5Output#1Copy31Input#2Copy50Output#2Copy2885DataConstraint首先,我们从小到大枚举\(n\),假设当前枚举......
  • cURL error 60: SSL certificate problem: unable to get local issuer certificate
    阿里云短信window报cURLerror60:SSLcertificateproblem:unabletogetlocalissuercertificate原文链接:https://blog.csdn.net/qq_41408081/article/details/124309075序:帮客户接一个阿里云短信验证码提醒,新版的SDK,一下,折磨简单,在Windows上搞的差点心力交瘁,差点怀疑......
  • CodeForces 1936E Yet Yet Another Permutation Problem
    洛谷传送门CF传送门首先设\(a_i=\max\limits_{j=1}^ip_j\),\(b_i=\max\limits_{j=1}^iq_j\)。直接容斥,钦定有多少值不同的\(a_i\)使得\(a_i=b_i\)。然后再把钦定的每种值转化成每种值第一次使得\(a_i=b_i\)的位置\(i\)。也就是说我们现在要钦定一些位置,......
  • Week 5 Problems
    T5判断对错:任意命题合式公式可以等价转化为复杂度不超过二的形式T6(2)今有一命题逻辑合式公式\(F_2\)为\[(P\rightarrowR)\rightarrow((Q\rightarrowR)\rightarrow(P\lorQ)\land\negR)\]根据Week1T1(1)中真值表写出\(F_2\)的主析取范式与主合取范式T7设命题逻辑合......
  • AT_arc175_a [ARC175A] Spoon Taking Problem 题解
    题目翻译link有\(N\)人围坐在一张圆桌旁,按逆时针顺序编号为\(1\)至\(N\)。每个人都有一个惯用手圆桌上有\(N\)把勺子,编号为\(1\)到\(N\),每对相邻的人之间放一把勺子给你一个\((1,\dots,N)\)的排列组合\((P_1,\dots,P_N)\)。在\(i=1,\dots,N\)的顺序中,人......
  • Problem Set #2
    书接上回14.P10253说唱题目这题怎么只有蓝的(我们考虑将答案写成位数的形式\((Ans=x_1x_2...x_n)\)那么我们考虑将\(y=\sum_ix_i\frac{10^{n-i+1}-1}{9}\)\(9y=\sum_ix_i(10^{n-i+1}-1)\)\(9y+\sumx_i=10\sum_ix_i10^{n-i}\)因为\(\sumx_i\leq5\times10^5......
  • My understanding of pedagogic metalanguage in "The Three-Body Problem "
    ......