zoukankan      html  css  js  c++  java
  • 欧拉函数 || LightOJ 1370 Bi-shoe and Phi-shoe

    给出x,求最小的y使y的欧拉函数大于等于x
    *解法:i).求出1e6之内的数的欧拉函数,遍历找
                ii).求比x大的第一个质数——因为每个质数n的欧拉函数都是n-1
    wa一次是因为SZ写小了……
    #include <iostream>
    #include <cstdio>
    using namespace std;
    #define SZ 1000005
    long long phi[SZ], a[SZ];
    void getphi(int n)
    {
        for(int i = 2; i <= n; i++) phi[i] = 0;
        phi[1] = 0;
        for(long long i = 2; i <= n; i++)
        {
            if(!phi[i])
                for(long long j = i; j <= n; j += i)
                {
                    if(!phi[j]) phi[j] = j;
                    phi[j] = phi[j] / i * (i - 1);
                }
        }
    }
    int main()
    {
        int T, cc = 0;
        scanf("%d", &T);
        phitable(SZ);
        while(T--)
        {
            int n;
            scanf("%d", &n);
            long long ans = 0;
            for(int i = 0; i < n; i++)
                scanf("%lld", &a[i]);
            sort(a, a+n);
            long long j = 0, i = 0;
            while(i < n)
            {
                if(a[i] > phi[j]) {j++; continue;}
                ans += j;
                i++;
            }
            printf("Case %d: %lld Xukha
    ", ++cc, ans);
        }
        return 0;
    }
  • 相关阅读:
    枚举enum
    C# 位运算符
    运算符&和&&以及|和||区别比较
    LINQ TO JSON
    LINQ 随机排序
    .NET Core LinQ
    CSharp笔记>>>多线程
    3D旋转
    CSharp 之CSkin的使用教程
    CSharp笔记>>>多语言,注册,模态对话框返回值
  • 原文地址:https://www.cnblogs.com/pinkglightning/p/8410660.html
Copyright © 2011-2022 走看看