zoukankan      html  css  js  c++  java
  • .

    素数区间

    include

    include<stdio.h>

    include<stdlib.h>

    include

    include

    include<float.h>

    include<string.h>

    include

    include

    include

    define sf scanf

    define pf printf

    define scf(x) scanf("%d",&x)

    define scff(x,y) scanf("%d%d",&x,&y)

    define prf(x) printf("%d ",x)

    define mm(x,b) memset((x),(b),sizeof(x))

    define rep(i,a,n) for (int i=a;i<n;i++)

    define per(i,a,n) for (int i=a;i>=n;i--)

    typedef long long ll;
    const ll mod=1e9+7;
    const double eps=1e-8;
    const int inf=0x3f3f3f3f;
    using namespace std;
    const double pi=acos(-1.0);
    const int N=1e5+7;
    bool sushu[N];
    void init()
    {
    mm(sushu,false);
    sushu[0]=sushu[1]=true;
    rep(i,2,N)
    {
    if(!sushu[i])
    {
    if(i>N/i) continue;
    for(int j=i*i;j<N;j+=i)
    sushu[j]=true;
    }
    }
    }
    int main()
    {
    init();
    int re,n;
    scf(re);
    while(re)
    {
    scf(n);
    if(n0||n1)
    {
    pf("0 ");continue;
    }
    if(!sushu[n])
    pf("0 ");
    else
    {
    int l,r;
    l=n;r=n;
    while(sushu[l-1])
    l--;
    while(sushu[r+1])
    r++;
    prf(r-l+1);
    }
    }
    return 0;
    }

    区间

    include

    include<stdio.h>

    include<stdlib.h>

    include

    include

    include<float.h>

    include<string.h>

    include

    include

    include

    define sf scanf

    define pf printf

    define scf(x) scanf("%d",&x)

    define scff(x,y) scanf("%d%d",&x,&y)

    define prf(x) printf("%d ",x)

    define mm(x,b) memset((x),(b),sizeof(x))

    define rep(i,a,n) for (int i=a;i<n;i++)

    define per(i,a,n) for (int i=a;i>=n;i--)

    typedef long long ll;
    const ll mod=1e9+7;
    const double eps=1e-8;
    const int inf=0x3f3f3f3f;
    using namespace std;
    const double pi=acos(-1.0);
    const int N=1e5+12;
    struct qujian
    {
    int l,r;
    }x[N];
    int main()
    {
    int n;scf(n);
    int maxn=0,minn=inf;
    rep(i,1,n+1)
    {
    scff(x[i].l,x[i].r);
    minn=min(minn,x[i].l);
    maxn=max(maxn,x[i].r);
    }
    rep(i,1,n+1)
    {
    if(x[i].lminn&&x[i].rmaxn)
    {
    prf(i);
    return 0;
    }
    }
    pf("-1 ");
    return 0;
    }

  • 相关阅读:
    从 Objective-C 里的 Alloc 和 AllocWithZone 谈起
    设计模式(26)
    iOS目录结构
    IOS didReceiveMemoryWarning 的那些事
    iOS多线程编程:线程同步总结
    我要进大厂之大数据Hadoop HDFS知识点(2)
    我要进大厂之大数据Hadoop HDFS知识点(1)
    我要进大厂之大数据ZooKeeper知识点(2)
    我要进大厂之大数据ZooKeeper知识点(1)
    rabbitmq使用延迟时报异常
  • 原文地址:https://www.cnblogs.com/wzl19981116/p/9617407.html
Copyright © 2011-2022 走看看