欧拉函数。

欧拉函数打表模板:

#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. wr720n v4 折腾笔记(二):刷入不死Uboot

    0x01 前言 接着上节刷入Openwrt开始说起,此次开始刷入不死Uboot,刷入之后就可以在Uboot里面随便刷机,再也不怕成砖了. 固件附件地址: 下载地址1(还是之前一的包) flash文件地 ...

  2. 洛谷 P2568 GCD 题解

    原题链接 庆祝一下:数论紫题达成成就! 第一道数论紫题.写个题解庆祝一下吧. 简要题意:求 \[\sum_{i=1}^n \sum_{j=1}^n [gcd(i,j)==p] \] 其中 \(p\) ...

  3. SQL 分组内求最大N个或最小N个

    题目描述 表 Employee +----+-------+--------+--------------+ | Id | Name | Salary | DepartmentId | +----+- ...

  4. 手把手教你学Git

    Git 使用手册独家实战 0.查看本机公钥 步骤: 1.进入.ssh目录 cd ~/.ssh 2.找到id_rsa.pub文件 ls / ll 3.查看文件 cat id_rsa.pub JackFe ...

  5. Nginx 实现API 网关

    1,网关 网关(Gateway)就是一个网络连接到另一个网络的“关口”. 在Nginx 配置负载均衡之后,可以进入到网关,在网关决定进入到哪个真实的web 服务器. 2,将Ngnix 配置 API 网 ...

  6. Python math库和random库

    1.math库 >>> from math import * >>> 2*pi 6.283185307179586 >>> e 2.7182818 ...

  7. nexus Maven私服的相关配置

    Maven私服中如需本地上传Maven私服内容则需在  setting.xml中配置如下: <server> <id>nexus-releases</id> < ...

  8. es6声明一个类

    js语言的传统方式是通过定义构造函数,生成心得对象.是一种基于原型的面向对象系统.在es6中增加了class类的概念,可以使用class关键字来声明一个类.之后用这个类来实例化对象. 构造函数示例 c ...

  9. 1026 Table Tennis (30分)

    A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For a ...

  10. Zabbix监控平台

                                                                     Zabbix监控平台 案例1:常用系统监控命令 案例2:部署Zabbi ...