欧拉函数。

欧拉函数打表模板:

#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. 解决vscode 没有 c++11 的代码提示(如to_string()等)

    2019.5.4 更新: 参考了stackflow上的一个问题:to_string is not a member of std, says g++ (mingw),发现直接换新版mingw即可- m ...

  2. 微信开发+百度AI学习:植物识别

    直接上代码 服务端代码如下 private static readonly Baidu.Aip.ImageClassify.ImageClassify client = new Baidu.Aip.I ...

  3. hdu2838 cow sorting用树状数组求逆序对

    题目链接:http://icpc.njust.edu.cn/Problem/Hdu/2838/ 题目解法:题目给出一个1-n的排列,操作只有一种:交换相邻的元素,代价是两个元素之和,问将该序列变成升序 ...

  4. 浅析jdbc建立连接方式与背后的java类加载

    关于jdbc的连接方式#1Connection conn;Class.forName("com.mysql.jdbc.Driver"); //2conn=DriverManager ...

  5. FormDataBodyPart获取表单文件名乱码解决方法

    FormDataMultiPart formData=; FormDataBodyPart filePart=; filePart.getFormDataContentDisposition().ge ...

  6. Redis 缓存更新一致性

    当执行写操作后,需要保证从缓存读取到的数据与数据库中持久化的数据是一致的,因此需要对缓存进行更新. 因为涉及到数据库和缓存两步操作,难以保证更新的原子性. 在设计更新策略时,我们需要考虑多个方面的问题 ...

  7. 使用skimage处理图像数据的9个技巧

    介绍 我们非常熟悉结构化(表格)数据的预处理步骤.你可以找到缺失的值然后添补它,然后检测并处理异常值,等等这些步骤.这有助于我们建立更好.更健壮的机器学习模型.但是当我们处理图像数据时,应该如何进行预 ...

  8. nginx IF 指令

    变量名可以使用"="或"!="运算符 ~ 符号表示区分大小写字母的匹配 "~*"符号表示不区分大小写字母的匹配 "!"和 ...

  9. C#接口多继承方法重名问题

    最近实现一个功能需要继承两个接口,然而父类接口有这重名的方法,且方法实现一致.两个父接口均被多个子接口继承,并在类实例中实现.起初,我是通过new重名方法来实现我的功能调用.后被指正,在网上看了一个工 ...

  10. 如何找回QQ聊天记录、语音、图片?

    多图长图预警,本教程适用于 安卓手机 认真仔细看完答案的成功几率翻倍哟! 请各位认真看答案!求您了~ 2020年/4/4日 更新 人民不会忘记,祖国不会忘记,我们不会忘记,先烈不朽. 调整答案顺序,使 ...