BZOJ2277 [Poi2011]Strongbox 【数论】
题目链接
题解
orz太难了
如果一个数\(x\)是密码,那么所有\((x,n)\)的倍数都是密码
如果两个数\(x,y\)是密码,那么所有\((x,y)\)的倍数都是密码
那么如果最后的密码集合为\(\{x_i\}\)那么一定存在一个\(x_i\)是剩余所有数的\(gcd\)
所以我们只需找最小的\(x | n\)且\(x | a_k\)且\(x \nmid a_i\)
那就找出\((a_k,n)\)的所有质因子,再用\((a_i,a_k,n)\)筛去不合法的即可
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define mp(a,b) make_pair<int,int>(a,b)
#define cls(s) memset(s,0,sizeof(s))
#define cp pair<int,int>
#define LL long long int
using namespace std;
const int maxn = 1000005,maxm = 10000005,INF = 1000000000;
inline LL read(){
LL out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
return out * flag;
}
LL n,k,a[maxn],L,fac[maxn],p[maxn],tot,cnt;
int vis[maxn];
LL gcd(LL a,LL b){return b ? gcd(b,a % b) : a;}
void getfac(){
LL x,tmp = L;
for (x = 1; x * x <= tmp; x++){
if (tmp % x == 0){
fac[++tot] = x;
if (x * x != tmp) fac[++tot] = tmp / x;
}
}
sort(fac + 1,fac + 1 + tot);
}
void getp(){
LL x,tmp = L;
for (x = 2; x * x <=tmp; x++)
if (tmp % x == 0){
p[++cnt] = x;
while (tmp % x == 0) tmp /= x;
}
if (tmp - 1) p[++cnt] = tmp;
}
int main(){
n = read(); k = read();
REP(i,k) a[i] = read();
L = gcd(n,a[k]);
getfac(); getp();
LL x;
for (int i = 1; i < k; i++){
x = gcd(a[i],L);
vis[lower_bound(fac + 1,fac + 1 + tot,x) - fac] = true;
}
for (int i = tot - 1; i; i--){
if (vis[i]) continue;
x = fac[i];
for (int j = 1; j <= cnt && x * p[j] <= L; j++){
LL y = x * p[j];
int pos = lower_bound(fac + 1,fac + 1 + tot,y) - fac;
if (fac[pos] == y && vis[pos]){
vis[i] = true;
break;
}
}
}
LL ans = 0;
for (int i = 1; i <= tot; i++)
if (!vis[i]){ans = n / fac[i]; break;}
printf("%lld\n",ans);
return 0;
}
BZOJ2277 [Poi2011]Strongbox 【数论】的更多相关文章
- BZOJ2277[Poi2011]Strongbox——数论
题目描述 Byteasar is a famous safe-cracker, who renounced his criminal activity and got into testing and ...
- bzoj 2277 [Poi2011]Strongbox 数论
2277: [Poi2011]Strongbox Time Limit: 60 Sec Memory Limit: 32 MBSubmit: 527 Solved: 231[Submit][Sta ...
- bzoj2277 [Poi2011]Strongbox
2277: [Poi2011]Strongbox Time Limit: 60 Sec Memory Limit: 32 MBSubmit: 498 Solved: 218[Submit][Sta ...
- 【BZOJ】2277: [Poi2011]Strongbox
题意 有一个密码箱,\(0\)到\(n-1\)中的某些整数是它的密码.如果\(a\)和\(b\)都是它的密码,那么\((a+b)%n\)也是它的密码(\(a,b\)可以相等).某人试了\(k\)次密码 ...
- BZOJ 2277 Poi2011 Strongbox
题目大意:一个集合A,包含了0~n-1这n个数.另有一个集合B,满足: 1.B是A的子集. 2.如果a.b均在B中,则(a+b)%n也在B中(a=b亦可) 给出k个数ai,前k-1个不在B中,第k个在 ...
- POI2011题解
POI2011题解 2214先咕一会... [BZOJ2212][POI2011]Tree Rotations 线段树合并模板题. #include<cstdio> #include< ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- POI做题笔记
POI2011 Conspiracy (2-SAT) Description \(n\leq 5000\) Solution 发现可拆点然后使用2-SAT做,由于特殊的关系,可以证明每次只能交换两个集 ...
- [poi2011]bzoj 2277 —— strongbox·[洛谷3518]
·问题描述· 有一个密码箱,0到n-1中的某些数是它的密码.且满足:如果a和b都是它的密码,那么(a+b)%n也是它的密码.某人试了k次密码,前k-1次都失败了,最后一次成功. 问:该密码箱最多有多少 ...
随机推荐
- Mysql 开启Federated引擎的方法
原文参考:http://www.thinksaas.cn/topics/0/63/63532.html 进入mysql命令行,没有看到Federated,说明没有安装 mysql>show en ...
- 深入理解C++中的Const,Mutable以及Volatile
我一直认为const表示一个常量,常量就是一个无法被修改的值,但是没有深入理解const的实现,甚至不知道mutable和volatile的存在,最近在书中看到了这一部分的知识,所以本文将详细解析这几 ...
- git clone、git pull和git fetch的用法及区别
声明:码字不易,转载请注明出处,欢迎文章下方讨论交流.Git 常用命令速查表 最近在一个学习小组里学习AI的课程,我们所有的学习资料和homework都放在gitlab上.今天一个小队友从gitlab ...
- eclipse查看源代码问题
最近分析源代码时,eclipse总是出错,显示org.eclipse.core.runtime.CoreException,解决方法:在builderpath点击 add external jars, ...
- TPO 02 - Desert Formation
TPO 02 - Desert Formation NOTE: 主要意思(大概就是主谓宾)用粗体标出:重要的其它用斜体: []中的是大致意思,可能与原文有关也可能无关,但不会离题 目的为训练句子/段落 ...
- RyuBook1.0案例三:REST Linkage
REST Linkage 该小结主要介绍如何添加一个REST Link 函数 RYU本身提供了一个类似WSGI的web服务器功能.借助这个功能,我们可以创建一个REST API. 基于创建的REST ...
- GitLab 搭建与使用
操作系统:Centos 7 环境:VM虚拟机 0x00:这里说下VM 虚拟机的配置 然后选择NAT模式 接下来配置网络 cd /etc/sysconfig/network-scripts/ 编辑:vi ...
- 7.hdfs工作流程及机制
1. hdfs基本工作流程 1. hdfs初始化目录结构 hdfs namenode -format 只是初始化了namenode的工作目录 而datanode的工作目录是在datanode启动后自己 ...
- HDU 5195 DZY Loves Topological Sorting 拓扑排序
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5195 bc(中文):http://bestcoder.hdu.edu.cn/contests ...
- 0527 SCRUM团队项目7.0
Sprint回顾 让我们一次比一次做得更好. 1.回顾组织 主题:“我们怎样才能在下个sprint中做的更好?” 时间:设定为1至2个小时. 参与者:整个团队. 场所:能够在不受干扰的情况下讨论. ...