Bi-shoe and Phi-shoe LightOJ - 1370
欧拉函数。
欧拉函数打表模板:
#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的更多相关文章
- 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 ...
- lightoj 1370 欧拉函数
A - Bi-shoe and Phi-shoe Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & % ...
- LightOJ 1370 - Bi-shoe and Phi-shoe (欧拉函数思想)
http://lightoj.com/volume_showproblem.php?problem=1370 Bi-shoe and Phi-shoe Time Limit:2000MS Me ...
- Lightoj 1370 素数打表 +二分
1370 - Bi-shoe and Phi-shoe PDF (English) Statistics Time Limit: 2 second(s) Memory Limit: 32 MB ...
- LightOJ 1370 Bi-shoe and Phi-shoe【欧拉函数 && 质数】
题目链接: http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1370 题意: 给定值,求满足欧拉值大于等于这个 ...
- LightOJ 1370 Bi-shoe and Phi-shoe 欧拉函数+线段树
分析:对于每个数,找到欧拉函数值大于它的,且标号最小的,预处理欧拉函数,然后按值建线段树就可以了 #include <iostream> #include <stdio.h> ...
- LightOJ - 1370
Bi-shoe and Phi-shoe Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %lld & %llu S ...
- LightOJ - 1370 Bi-shoe and Phi-shoe (欧拉函数打表)
题意:给N个数,求对每个数ai都满足最小的phi[x]>=ai的x之和. 分析:先预处理出每个数的欧拉函数值phi[x].对于每个数ai对应的最小x值,既可以二分逼近求出,也可以预处理打表求. ...
- 欧拉函数 || LightOJ 1370 Bi-shoe and Phi-shoe
给出x,求最小的y使y的欧拉函数大于等于x *解法:i).求出1e6之内的数的欧拉函数,遍历找 ii).求比x大的第一个质数——因为每个质数n的欧拉函数都是n-1 wa一次是因 ...
- 【LightOJ - 1370】Bi-shoe and Phi-shoe
Bi-shoe and Phi-shoe Descriptions: 给出一些数字,对于每个数字找到一个欧拉函数值大于等于这个数的数,求找到的所有数的最小和. Input 输入以整数T(≤100)开始 ...
随机推荐
- RabbitMQ 在Ubuntu18.04上的安装
1.安装erlang由于rabbitMq需要erlang语言的支持,在安装rabbitMq之前需要安装erlang sudo apt-get install erlang2.安装Rabbitmq更新源 ...
- P4147 玉蟾宫 题解
原题链接 简要题意: 求最大 \(0\) 矩阵.(将字符转化为数字) 本题是模板题,可以用来爆踩.??? 悬线法 来了! 其中绿色是 \(0\),红色是 \(1\). 下面以这个图为例讲一下算法流程. ...
- 关于js中iframe 中 location.href的用法
关于js中"window.location.href"."location.href"."parent.location.href".&qu ...
- [阿里云-机器学习PAI快速入门与业务实战 ]课时1-机器学习背景知识以及业务架构介绍
什么是机器学习? 机器学习指的是机器通过统计学算法,对大量的历史数据进行学习从而生成经验模型,利用经验模型指导业务. 目前机器学习主要在一下一些方面发挥作用: 营销类场景:商品推荐.用户群体画像.广告 ...
- postgre安装和使用(R&Python)
安装postgre http://helianthus-code.lofter.com/post/1dfe03e0_1c68233aa 这里选C更好 这里口令密码输入就是黑的 我装的时候反复报错,查了 ...
- OpenCV-Python 使用OCR手写数据集运行KNN | 五十四
目标 在本章中 我们将使用我们在kNN上的知识来构建基本的OCR应用程序. 我们将尝试使用OpenCV自带的数字和字母数据集. 手写数字的OCR 我们的目标是构建一个可以读取手写数字的应用程序.为此, ...
- SSH免密配置
1. 在三个节点生成秘钥cd ~/.sshssh-keygen -t rsa 2.合并三个节点的密码cat id_rsa.pub >> authorized_keysssh postgre ...
- Cplex教育版申请
任何人:直接在公众号"毒书 彼记" ,“资源下载” 板块下载: 如果你的学校没有购买cplex软件没那么,你就不可以下载教育版的cplex软件,如过下载免费板,它的功能会有一些限制 ...
- SpringCloud入门(八): Zuul 过滤器详解
Zuul 过滤器 zuul 有四种过滤器类型,分别是: 1.Pre:过滤器在请求被路由之前调用.我们可利用这种过滤器实现身份验证.在集群中选择请求的微服务.记录调试信息等: 2.Routing:过滤器 ...
- 安装 MySQL 过程记录
最近安装 MySQL 时 遇到了许多问题,记录一下安装过程以及遇到的问题. 第一步:在官网上下载适合自己版本的 MySQL,我选择的是 Windows 64 位免安装版的: 官网地址:https ...