zoukankan      html  css  js  c++  java
  • codevs 1462 素数和

    1462 素数和

     
    题目描述 Description

    给定2个整数a,b 求出它们之间(不含a,b)所有质数的和。

    输入描述 Input Description

    一行,a b(0<=a,b<=65536)

    输出描述 Output Description

    一行,a,b之间(不含a,b)所有素数的和。

    样例输入 Sample Input

    39 1224

    样例输出 Sample Output

    111390

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    using namespace std;
    int main()
    {
        int flag=0,a,b,tot=0;
        scanf("%d%d",&a,&b);
        if(a>b)swap(a,b);
        for(int i=a+1;i<b;++i)
        {
            flag=1;
            for(int j=2;j<=sqrt(i);++j)
            {
                if(i%j==0)
                {
                    flag=0;
                    break;
                }
            }
            if(flag==1)
                tot+=i;
        }
        printf("%d",tot);
        return 0;
    }

    swap即交换括号内逗号分隔的两参数

  • 相关阅读:
    单调队列+二分 G
    dp cf 1700 最近几天的刷题
    dp 20190618
    dp 20190617
    dp cf 20190615
    dp cf 20190614
    powercli
    zabbix docker-weixin
    cenetos-大文件排序
    esxcli命令
  • 原文地址:https://www.cnblogs.com/kuaileyongheng/p/6710959.html
Copyright © 2011-2022 走看看