light_oj 1370 欧拉函数+二分

light_oj 1370 欧拉函数+二分

A - Bi-shoe and Phi-shoe

Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Submit Status

Description

Bamboo Pole-vault is a massively popular sport in Xzhiland. And Master Phi-shoe is a very popular coach for his success. He needs some bamboos for his students, so he asked his assistant Bi-Shoe to go to the market and buy them. Plenty of Bamboos of all possible integer lengths (yes!) are available in the market. According to Xzhila tradition,

Score of a bamboo = Φ (bamboo‘s length)

(Xzhilans are really fond of number theory). For your information, Φ (n) = numbers less than n which are relatively prime (having no common divisor other than 1) to n. So, score of a bamboo of length 9 is 6 as 1, 2, 4, 5, 7, 8 are relatively prime to 9.

The assistant Bi-shoe has to buy one bamboo for each student. As a twist, each pole-vault student of Phi-shoe has a lucky number. Bi-shoe wants to buy bamboos such that each of them gets a bamboo with a score greater than or equal to his/her lucky number. Bi-shoe wants to minimize the total amount of money spent for buying the bamboos. One unit of bamboo costs 1 Xukha. Help him.

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing an integer n (1 ≤ n ≤ 10000) denoting the number of students of Phi-shoe. The next line contains n space separated integers denoting the lucky numbers for the students. Each lucky number will lie in the range [1, 106].

Output

For each case, print the case number and the minimum possible money spent for buying the bamboos. See the samples for details.

Sample Input

3

5

1 2 3 4 5

6

10 11 12 13 14 15

2

1 1

Sample Output

Case 1: 22 Xukha

Case 2: 88 Xukha

Case 3: 4 Xukha

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<math.h>
#include<cctype>

using namespace std;

typedef long long ll;
const int maxn=2000100;
const int INF=(1<<29);
const double EPS=0.0000000001;
const double Pi=acos(-1.0);

int n;
int euler[maxn];

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

int main()
{
    int T;cin>>T;
    int tag=1;
    Init();
    for(int i=2;i<maxn;i++) euler[i]=max(euler[i],euler[i-1]);
    while(T--){
        cin>>n;
        ll ans=0;
        while(n--){
            int t;
            scanf("%d",&t);
            ans+=lower_bound(euler+2,euler+maxn,t)-euler;
        }
        printf("Case %d: %lld Xukha\n",tag++,ans);
    }
    return 0;
}

时间: 2024-10-09 22:24:30

light_oj 1370 欧拉函数+二分的相关文章

LightOJ 1370 欧拉函数

1.LightOJ 1370  Bi-shoe and Phi-shoe   欧拉函数 2.总结: #include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorithm> #include<cstdio> #define max(a,b) a>b?a:b #define F(i,a,b) for (int i=a;i<

LIGHT OJ 1370 欧拉函数(在小于自身的正整数中有n个与自身互素的数,这样的数最小的为n后第一个素数)

1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<string> 5 #include<algorithm> 6 #include <cmath> 7 using namespace std; 8 typedef long long ll; 9 const ll INF = -100000000000ll; 10 const double ep

Ligh OJ 1370 Party All the Time (欧拉函数 +素数打表)

1370 - Bi-shoe and Phi-shoe PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Bamboo Pole-vault is a massively popular sport in Xzhiland. And Master Phi-shoe is a very popular coach for his success. He needs some bamboos for

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

http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1370 题意: 给一些数Ai(第 i 个数),Ai这些数代表的是某个数欧拉函数的值,我们要求出数 Ni 的欧拉函数值不小于Ai.而我们要求的就是这些 Ni 这些数字的和sum,而且我们想要sum最小,求出sum最小多少. 思路:素数P的欧拉函数值为P-1. 所以对于一个给出的数,我们去寻找大于它的第一个素数即可. 1 #include<iostream>

LightOJ Bi-shoe and Phi-shoe 1370【欧拉函数+素数打表】

1370 - Bi-shoe and Phi-shoe PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Bamboo Pole-vault is a massively popular sport in Xzhiland. And Master Phi-shoe is a very popular coach for his success. He needs some bamboos for

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

分析:对于每个数,找到欧拉函数值大于它的,且标号最小的,预处理欧拉函数,然后按值建线段树就可以了 #include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #include <cmath> #include <map> using namespace std; typedef long long LL; const int N = 1

欧拉函数 || 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 <

bzoj 2818 GCD 数论 欧拉函数

bzoj[2818]Gcd Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. Input 一个整数N Output 如题 Sample Input 4 Sample Output 4 HINT hint对于样例(2,2),(2,4),(3,3),(4,2) 1<=N<=10^7 题解一(自己yy) phi[i]表示与x互质的数的个数 即gcd(x,y)=1 1<=y<x ∴对于x,y 若a为素数 则gcd(xa,

Bi-shoe and Phi-shoe(欧拉函数)

Bi-shoe and Phi-shoe Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1370 Description Bamboo Pole-vault is a massively popular sport in Xzhiland. And Master Phi-shoe is a very popular coach fo