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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值