• .


    素数区间

    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;
    }

  • 相关阅读:
    <C> 链表 双向链表 栈 队列
    <C> 结构体
    <C> getchar()函数 如何把getchar()到的字符串存起来的实际应用
    DataSet转换为泛型集合和DataRow 转成 模型类
    对DataSet,DataRow,DateTable转换成相应的模型
    Json对象与Json字符串互转(4种转换方式)
    Android开发 使用HBuilder的缓存方法
    MIT_AI公开课p1p2学习笔记
    LeetCode_02 两数相加【链表】
    leetcode_01两数之和
  • 原文地址:https://www.cnblogs.com/wzl19981116/p/9617407.html
Copyright © 2020-2023  润新知