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

Source

Problem Setter: Mir Wasi Ahmed
Special Thanks: F.A. Rezaur Rahman Chowdhury, Jane Alam Jan
/**
题意:f(n) 表示 小于等于 n 的数中素数的个数;给出一串数 比如x 求f(x) >= x 的最小和
做法:欧拉函数
**/
#include <iostream>
#include<cmath>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<stack>
#define maxn 1000000 + 10
int mindiv[maxn],phi[maxn],sum[maxn];
int mmap[maxn];
int mmpp[maxn];
using namespace std;
void solve()
{
for(int i=; i<maxn; i++)
{
mindiv[i] = i;
}
for(int i=; i*i<maxn; i++)
{
if(mindiv[i] == i)
{
for(int j=i*i; j<maxn; j+=i)
{
mindiv[j] = i;
}
}
}
phi[] = ;
for(int i=; i<maxn; i++)
{
phi[i] = phi[i/mindiv[i]];
if((i/mindiv[i])%mindiv[i] == )
{
phi[i] *=mindiv[i];
}
else
{
phi[i] *= mindiv[i] -;
}
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
int T;
scanf("%d",&T);
int n;
solve();
int Case = ;
while(T--)
{
scanf("%d",&n);
int res = ;
long long sum = ;
for(int i=; i<n; i++)
{
scanf("%d",&mmpp[i]);
}
sort(mmpp,mmpp+n);
int tt= ,Index = ;
int j = ;
phi[] = ;
for(int i=; i<n; )
{
if(phi[j] >= mmpp[i])
{
sum += j;
i++;
}
else j++;
}
printf("Case %d: %lld Xukha\n",Case++,sum);
}
return ;
}

LightOJ - 1370的更多相关文章

  1. lightoj 1370 欧拉函数

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

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

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

  3. LightOJ 1370 Bi-shoe and Phi-shoe

    /* LightOJ 1370 Bi-shoe and Phi-shoe http://lightoj.com/login_main.php?url=volume_showproblem.php?pr ...

  4. LightOJ 1370 Bi-shoe and Phi-shoe【欧拉函数 && 质数】

    题目链接: http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1370 题意: 给定值,求满足欧拉值大于等于这个 ...

  5. Lightoj 1370 素数打表 +二分

    1370 - Bi-shoe and Phi-shoe   PDF (English) Statistics   Time Limit: 2 second(s) Memory Limit: 32 MB ...

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

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

  7. LightOJ 1370 Bi-shoe and Phi-shoe 数论

    题目大意:f(x)=n 代表1-x中与x互质的数字的个数.给出n个数字a[i],要求f(x)=a[i],求x的和. 思路:每个素数x 有x-1个不大于x的互质数.则f(x)=a[i],若a[i]+1为 ...

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

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

  9. [LightOJ 1370] Bi-shoe and Phi-shoe(欧拉函数快速筛法)

    题目链接: https://vjudge.net/problem/LightOJ-1370 题目描述: 给出一些数字,对于每个数字找到一个欧拉函数值大于等于这个数的数,求找到的所有数的最小和. 知识点 ...

随机推荐

  1. BZOJ2006 [NOI2010]超级钢琴 【堆 + RMQ】

    2006: [NOI2010]超级钢琴 Time Limit: 20 Sec  Memory Limit: 552 MB Submit: 3446  Solved: 1692 [Submit][Sta ...

  2. SSO解决session共享的几种方案

    之前做项目遇到了这个sso系统,当时只是理解了一部分,今天偶尔发现一篇文章,觉得写的不错,增加了sso知识: 单点登录在现在的系统架构中广泛存在,他将多个子系统的认证体系打通,实现了一个入口多处使用, ...

  3. UVA 11922 Splay tree

    UVA 11922 题意: 有n个数1~n 操作a,b表示取出第a~b个数,翻转后添加到数列的尾部 输入n,m 输入m条指令a,b 输出最终的序列 代码: #include<iostream&g ...

  4. shell编程:条件测试与比较(六)

    条件测试方法综述 test条件测试的简单语法及测试 范例6-1 测试文件(在test命令中使用-f选项:文件存在且为不同文件则表达式成立) [root@adminset ~]# test -f fil ...

  5. [技巧篇]11.JavaScript原生态如何获取浏览器请求地址中的参数

    var getAccessParams = function(){ var i,ilen,strs,keyName,keyValue, params={}, path = window.locatio ...

  6. MongoDB入门(1)- MongoDB简介

    什么是MongoDB NoSQL NoSQL systems are also sometimes called "Not only SQL" to emphasize that ...

  7. 【设计模式】 模式PK:包装模式群PK

    1.概述 我们讲了这么多的设计模式,大家有没有发觉在很多的模式中有些角色是不干活的?它们只是充当黔首作用,你有问题,找我,但我不处理,我让其他人处理.最典型的就是代理模式了,代理角色接收请求然后传递到 ...

  8. node起本地服务器以及实现代理,前端接口转发

    上一篇文章写了使用docker来做nginx镜像实现本地的页面代理以及接口转发,但是需要下载docker,这个对于很多人来说还是显得比较麻烦,于是这个文章就是介绍如何只用node就可以代理本地的页面和 ...

  9. 首行缩进css

    html首行缩进2字符,可以使用CSS属性中的[text-indent]进行设置. 设置代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1 ...

  10. bzoj 1968 数学

    在1-n所有数中,i一共可以成为n/i个数的约数,也即所有的约数中有n/i个i,所以扫一遍累加答案就好了. /********************************************* ...