• LightOJ 1370 Bi-shoe and Phi-shoe【欧拉函数 && 质数】


    题目链接:

    http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1370

    题意:

    给定值,求满足欧拉值大于等于这个数的最小的数。

    分析:

    两个质数之间的合数的欧拉值小于较小的质数,所以满足比给定的值大的欧拉值肯定是大于这个数的第一个质数。
    二分查找一下就好了。

    代码:

    #include <iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<cmath>
    using namespace std;
    const int maxn = 1e6 + 5;
    int flag[maxn], prime[maxn];
    typedef long long ll;
    int tot = 0;
    void getprime()
    {
        fill(flag, flag + maxn, 1);
        for(int i = 2; i < maxn; i++){
            if(flag[i]){
                prime[tot++] = i;
                for(int j = 2 * i; j < maxn; j += i){
                    flag[j] = 0;
                }
            }
        }
    }
    int main (void)
    {
        int n;
        getprime();
        int T;cin>>T;
        int cnt = 0;
        while(T--){
            cnt++;
            cin>>n;
            ll res = 0;
            int a;
            for(int i = 0; i < n; i++){
                cin>>a;
                int tmp = upper_bound(prime, prime + tot, a) - prime;
                res += prime[tmp];
            }
            cout<<"Case "<<cnt<<": "<<res<<" Xukha"<<endl;
        }
        return 0;
    }
  • 相关阅读:
    zabbix key 模样
    windows key代码
    windows更新代理地址配置
    Proftpd搭建
    SAS界面标题乱码
    jenkins-2.225部署
    DNS 安全详解
    DNS搭建
    修复linux登录超时问题
    prometheus安装全过程
  • 原文地址:https://www.cnblogs.com/Tuesdayzz/p/5758661.html
Copyright © 2020-2023  润新知