欧拉函数。

欧拉函数打表模板:

#define maxn 3000010
int p[maxn];
void oula(){
int i,j;
for(i=; i<=maxn; i++)
p[i]=i;
for(i=; i<=maxn; i+=)
p[i]/=;
for(i=; i<=maxn; i+=)
if(p[i]==i)
{
for(j=i; j<=maxn; j+=i)
p[j]=(p[j]/i*(i-));
}
}

题解:(说明:要不是看题解,自己真不敢这样写....,只能说数据有点弱。)

将欧拉函数打完表后,先将每个幸运数字排序一下。

然后枚举长度的同时,枚举每个幸运数字,如果当前长度对应的欧拉值大于等于幸运数字。直接就加上。

code1:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e9+;
const ll maxn=1e6+;
const ll N=1E6+;
ll p[N];
ll arr[N];
ll dp[N];
void oula(){
for(ll i=;i<=maxn;i++) p[i]=i;
for(ll i=; i<=maxn; i+=) p[i]/=;
for(ll i=; i<=maxn; i+=)
if(p[i]==i){
for(ll j=i; j<=maxn; j+=i)
p[j]=(p[j]/i*(i-));
}
}
void solve(ll time){
ll n;
cin>>n;
ll ans=;
for(ll i=;i<=n;i++) cin>>arr[i];
sort(arr+,arr++n);
for(int i=,j=;i<=n&&j<maxn;j++){
while(p[j]>=arr[i]&&i<=n) {
ans+=j;
i++;
}
}
printf("Case %d: ",time);
cout<<ans<<" Xukha\n";
}
int main(){
oula();
ll t;
cin>>t;
for(ll i=;i<=t;i++) solve(i);
return ;
}

我的思路和code2差不多,但是我的一直调不对。。。

用一个数组dp,记录每个幸运数字对应的长度的最小值。

对一个长度i,其对应的欧拉值。枚举小于当前欧拉值并且还没有赋值的(可能没有对应长度,或者对应长度在后边)欧拉值赋值长度i。这样可以保证当前欧拉值为j,dp[j]可以表示,大于等于j的欧拉值所对应的最小长度。

秒~~

code2:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=1e6+;
const ll N=1E6+;
ll p[N];
ll arr[N];
ll dp[N];
void oula(){
for(ll i=;i<=maxn;i++) p[i]=i;
for(ll i=; i<=maxn; i+=) p[i]/=;
for(ll i=; i<=maxn; i+=)
if(p[i]==i){
for(ll j=i; j<=maxn; j+=i)
p[j]=(p[j]/i*(i-));
}
}
void solve(ll time){
ll n;
cin>>n;
ll ans=;
for(ll i=;i<=n;i++){
ll x;
cin>>x;
ans+=dp[x];
}
printf("Case %d: %d Xukha\n",time,ans);
}
int main(){
oula();
memset(dp,,sizeof dp);
for(ll i=;i<=maxn;i++){
for(ll j=p[i];dp[j]==&&j>=;j--)
dp[j]=i;
}
dp[]=;
ll t;
cin>>t;
for(ll i=;i<=t;i++) solve(i);
return ;
}

Bi-shoe and Phi-shoe LightOJ - 1370的更多相关文章

  1. 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 ...

  2. lightoj 1370 欧拉函数

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

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

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

  4. Lightoj 1370 素数打表 +二分

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

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

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

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

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

  7. LightOJ - 1370

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

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

    题意:给N个数,求对每个数ai都满足最小的phi[x]>=ai的x之和. 分析:先预处理出每个数的欧拉函数值phi[x].对于每个数ai对应的最小x值,既可以二分逼近求出,也可以预处理打表求. ...

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

    给出x,求最小的y使y的欧拉函数大于等于x *解法:i).求出1e6之内的数的欧拉函数,遍历找             ii).求比x大的第一个质数——因为每个质数n的欧拉函数都是n-1 wa一次是因 ...

  10. 【LightOJ - 1370】Bi-shoe and Phi-shoe

    Bi-shoe and Phi-shoe Descriptions: 给出一些数字,对于每个数字找到一个欧拉函数值大于等于这个数的数,求找到的所有数的最小和. Input 输入以整数T(≤100)开始 ...

随机推荐

  1. hdu1171kmp果题

    题目链接:http://icpc.njust.edu.cn/Problem/Hdu/1711/ #include<bits/stdc++.h> using namespace std; t ...

  2. P2341 [USACO03FALL][HAOI2006]受欢迎的牛 G 题解

    原题链接 POJ的链接 简要题意: 给定一张图,求多少个点,每个点都能到达它. 本题作为强连通分量的入门题. 何为强连通分量?有什么用? 下面一一解释. 首先,我们要确认,这道题目如果不用强连通分量而 ...

  3. CF1324E Sleeping Schedule 题解

    原题链接 简要题意: 每次可以将 \(a_i\) 减 \(1\) 或不变.求让 \(a_i\) 的前缀和 \(\% h\) 的值在 \([l,r]\) 区间中的最多的个数. E题是个水dp,也不怎样 ...

  4. 服务器模型---socket!!!

    /*********************服务器模型******************/ 一.循环服务器:循环服务器在同一时刻只可以相应一个客户端请求: 二.并发服务器:并发服务器在同一时刻可以相 ...

  5. Transformers 简介(上)

    作者|huggingface 编译|VK 来源|Github Transformers是TensorFlow 2.0和PyTorch的最新自然语言处理库 Transformers(以前称为pytorc ...

  6. vs编译器中不允许使用scanf()的情况

    问题1描述: vs编译器中,不允许使用scanf()函数. error C4996: 'scanf': This function or variable may be unsafe. Conside ...

  7. WePY的开发环境的安装

    2020-03-24 1.安装Node.js 官网:https://nodejs.org/ 两个版本 LTS为稳定的长期支持版本 Current为最新的版本 安装完毕后,cmd下输入 node -v ...

  8. n次方

    1.问题描述 计算 an 2.算法分析 先将 n 变一变,寻找新的计算路径.预处理就是变治法的根本. 如果单纯循环执行 n 次相乘,那么时间复杂度为 O(n).可以利用二进制幂大大改进效率. 主要思路 ...

  9. BurpSuit工具安装和基本使用方法

    burpsuite是渗透的必备工具,使用它可以进行一些截包分析,修改包数据.暴力破解.扫描等功能,使用最多的场景应该是设置代理拦截数据包分析数据和爆破. JDK工具下载和安装(可选) 运行BurpSu ...

  10. 实验四 数据查询3-group by等

    实验四 数据库查询 一.  实验内容: 1. Group by语句 2. Having 语句 3. Order by语句 4. Limit语句 5. Union语句 6. Handler语句 二.  ...