给出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 = ; i <= n; i++) phi[i] = ;
phi[] = ;
for(long long i = ; 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 - );
}
}
}
int main()
{
int T, cc = ;
scanf("%d", &T);
phitable(SZ);
while(T--)
{
int n;
scanf("%d", &n);
long long ans = ;
for(int i = ; i < n; i++)
scanf("%lld", &a[i]);
sort(a, a+n);
long long j = , i = ;
while(i < n)
{
if(a[i] > phi[j]) {j++; continue;}
ans += j;
i++;
}
printf("Case %d: %lld Xukha\n", ++cc, ans);
}
return ;
}

欧拉函数 || LightOJ 1370 Bi-shoe and Phi-shoe的更多相关文章

  1. 数论-欧拉函数-LightOJ - 1370

    我是知道φ(n)=n-1,n为质数  的,然后给的样例在纸上一算,嗯,好像是找往上最近的质数就行了,而且有些合数的欧拉函数值还会比比它小一点的质数的欧拉函数值要小,所以坚定了往上找最近的质数的决心—— ...

  2. zoj 2777 Visible Lattice Points(欧拉函数,基础)

    题目 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string.h> #include<algo ...

  3. UVA 11424 GCD - Extreme (I) (欧拉函数+筛法)

    题目:给出n,求gcd(1,2)+gcd(1,3)+gcd(2,3)+gcd(1,4)+gcd(2,4)+gcd(3,4)+...+gcd(1,n)+gcd(2,n)+...+gcd(n-1,n) 此 ...

  4. P2158 [SDOI2008] 仪仗队(欧拉函数模板)

    题目描述 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是否整齐(如下图 ...

  5. GuGuFishtion HDU - 6390 (欧拉函数,容斥)

    GuGuFishtion \[ Time Limit: 1500 ms\quad Memory Limit: 65536 kB \] 题意 给出定义\(Gu(a, b) = \frac{\phi(ab ...

  6. lightoj 1370 欧拉函数

    A - Bi-shoe and Phi-shoe Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & % ...

  7. LightOJ 1370 - Bi-shoe and Phi-shoe (欧拉函数思想)

    http://lightoj.com/volume_showproblem.php?problem=1370 Bi-shoe and Phi-shoe Time Limit:2000MS     Me ...

  8. LightOJ 1370 Bi-shoe and Phi-shoe 欧拉函数+线段树

    分析:对于每个数,找到欧拉函数值大于它的,且标号最小的,预处理欧拉函数,然后按值建线段树就可以了 #include <iostream> #include <stdio.h> ...

  9. LightOJ 1370 Bi-shoe and Phi-shoe(欧拉函数)

    题意:题目给出一个欧拉函数值F(X),让我们求>=这个函数值的最小数N,使得F(N) >= F(X); 分析:这个题目有两种做法.第一种,暴力打出欧拉函数表,然后将它调整成有序的,再建立一 ...

随机推荐

  1. NYOJ5——Binary String Matching

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3  描述:Given two strings A and B, whose alph ...

  2. JAVA基础-面向对象06

    一.封装 1. 封装概念和体现 封装:包装的意思,隐藏被封装的事物的信息:生活中的包装:快递:食品:电子产品……方便:好看易用:安全: Java程序中的包装: 类:包装了同一类事物的共性信息: 函数: ...

  3. sublime text3安装配置c++环境(windows+ubuntu)

    1.下载sublime text3 官网地址:http://www.sublimetext.com/3 ubuntu直接在Ubuntu Software中搜索sublime安装 2.配置环境变量(wi ...

  4. poj 2960 S-Nim【SG函数】

    预处理出SG函数,然后像普通nim一样做即可 #include<iostream> #include<cstdio> using namespace std; const in ...

  5. hdu 1171 Big Event in HDU【生成函数】

    按套路列生成函数式子然后暴力乘,这样复杂度看起来非常大,但是可以动态维护最大值,这样就是O(能过)的了 仔细想想这个多项式暴力乘理解成背包dp也行? #include<iostream> ...

  6. AspectCore的AOP操作

    AOP实现缓存的一个例子 using AspectCore.DynamicProxy; using Microsoft.Extensions.Caching.Memory; [AttributeUsa ...

  7. SQL中进行转列的几种方式

    SQL中进行转列 在很多笔试的程序员中会有很多写SQL的情况,其中很多时候会考察行转列.那么这个时候如果能写出来几种行转列的SQL,会给面试官留下比较好的印象. 以下是这次sql转换的表结构以及数据 ...

  8. 洛谷 P4135 作诗

    分块大暴力,跟区间众数基本一样 #pragma GCC optimize(3) #include<cstdio> #include<algorithm> #include< ...

  9. G. 24 观察 + 树状数组

    http://codeforces.com/gym/101257/problem/G 首先要看到题目,题目是本来严格大于score[i] > score[j].然后score[i] < s ...

  10. RHEL 6.5----Varnish缓存服务器

    主机名 IP  服务  master  192.168.30.130   varnish   slave  192.168.30.131  httpd WebServer   192.168.30.1 ...