欧拉函数。

欧拉函数打表模板:

#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. Hive支持的文件格式和压缩格式及各自特点

    Hive中的文件格式 1-TEXTFILE 文本格式,Hive的默认格式,数据不压缩,磁盘开销大.数据解析开销大. 对应的hive API为:org.apache.hadoop.mapred.Text ...

  2. Node/Python 工具搭建cmder和nrm

    一.安装cmder cmder是windows下的一款终端工具,支持很多linux命令,用起来还是很爽的. 1.安装 http://cmder.net/ 直接在官网下载,解压即可. 2.cmder配置 ...

  3. Spring05——Spring 如何实现事务管理

    在此之前,我们已经了解了 Spring 相关的基础知识,今天将为给位带来,有关 Spring 事务代理的相关知识.关注我的公众号「Java面典」,每天 10:24 和你一起了解更多 Java 相关知识 ...

  4. 在Windows Python3.4 上安装NumPy、Matplotlib、SciPy和IPython

    NumPy 下载地址: http://sourceforge.net/projects/numpy/files/NumPy/1.8.1/ SciPy 下载地址: http://sourceforge. ...

  5. 通过源码理解Spring中@Scheduled的实现原理并且实现调度任务动态装载

    前提 最近的新项目和数据同步相关,有定时调度的需求.之前一直有使用过Quartz.XXL-Job.Easy Scheduler等调度框架,后来越发觉得这些框架太重量级了,于是想到了Spring内置的S ...

  6. OpenCV-Python ORB(面向快速和旋转的BRIEF) | 四十三

    目标 在本章中,我们将了解ORB的基础知识 理论 作为OpenCV的狂热者,关于ORB的最重要的事情是它来自" OpenCV Labs".该算法由Ethan Rublee,Vinc ...

  7. PyTorch专栏(五):迁移学习

    专栏目录: 第一章:PyTorch之简介与下载 PyTorch简介 PyTorch环境搭建 第二章:PyTorch之60分钟入门 PyTorch入门 PyTorch自动微分 PyTorch神经网络 P ...

  8. SVM | 支持向量机原理讲解(二)

    一.线性可分的支持向量机存在的问题 在支持向量机一中,我们介绍了当数据集是线性可分的时候,我们可以使用线性可分的支持向量机将数据进行分类(由于隔了很长时间才更新,因此忘记了支持向量机一的读者可以回看支 ...

  9. 初识js(第一篇)

    初识javascript js是前端中作交互控制的语言,有了它,我们的前端页面才能"活"起来.学好这么语言显得非常重要,但是存在一定难度,所以一定要认真学习,充满耐心. js书写规 ...

  10. MATLAB——元胞数组

    一. 1.元胞数组的创建 >> a={;ones(,),:} a = ] [2x3 ;ones(,),:} >> b=[{};{ones(,)},{:}] b = ] [2x3 ...