其他分享
首页 > 其他分享> > Bi-shoe and Phi-shoe(欧拉函数模板题)

Bi-shoe and Phi-shoe(欧拉函数模板题)

作者:互联网

https://www.csdn.net/link/?target_url=https%3A%2F%2Fvjudge.net%2Fproblem%2FLightOJ-1370&id=71192453&token=b8b8a5128d97274aa569f02eb01ee1e0

#include <iostream>
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
const int maxn = 1e6+50;
int phi[maxn];

void phi_table()//打标
{
    memset(phi, 0, sizeof(phi));
    phi[1] = 0;//按照题意 

    for(int i = 2;i < maxn;i++)
    {
        if(!phi[i])
        {
            for(int j = i;j < maxn;j+=i)
            {
                if(!phi[j])phi[j] = j;
                phi[j] = phi[j]/i*(i-1);
            }
        }
    }


}
int lucky[maxn];
int main()
{
    ios::sync_with_stdio(false);
    int T;
    int cnt = 0;
    phi_table();
    cin>>T;
    while(T--)
    {
        cnt++;
        int n;
        ll ans = 0;
        cin>>n;
        for(int i = 0;i < n;i++)
        {
            cin>>lucky[i];

            for(int j = lucky[i]+1;j < maxn;j++)
            {
                if(phi[j] >= lucky[i])
                {

                    ans+=j;break;
                }
            }

        }
        cout<<"Case "<<cnt<<": "<<ans<<" Xukha"<<endl;



    }
    return 0;
}


标签:phi,cin,int,Phi,lucky,Bi,++,maxn,shoe
来源: https://blog.csdn.net/qq_43824791/article/details/99697153