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次都失败了,最后一次成功. 问:该密码箱最多有多少 ...
随机推荐
- git远程版本回滚方法【转】
step1:本地代码回滚到上一版本(或者指定版本) git reset --hard HEAD~1 step2:加入-f参数,强制提交,远程端将强制跟新到reset版本 git push -f ori ...
- Intellij IDEA破解激活
本文使用破解补丁激活Intellij IDEA 第一步:下载破解补丁(http://idea.lanyus.com/) 第二步:将下载好的补丁放置磁盘的任意位置,下面是我放置的位置 第三步:打开Int ...
- ubuntu/linux系统中安装jdk以及eclipse(附图解详细步骤)
1.首先得先下载JDK和eclipsejdk下载网址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-21 ...
- 初创型公司如何经济有效的申请邓白氏编码(DUNS)
听说有免费,和800元,1500元,上万元等不同的申请方式?听说申请完还要等十数个工作日让邓白氏和苹果的数据库同步.不同高低价格的申请方式得到的编码都能被苹果接受吗? http://www.zhihu ...
- ES6的新特性(5)——数值的扩展
数值的扩展 二进制和八进制表示法 ES6 提供了二进制和八进制数值的新的写法,分别用前缀0b(或0B)和0o(或0O)表示. 0b111110111 === 503 // true 0o767 === ...
- xpath获取同级元素
XPath轴(XPath Axes)可定义某个相对于当前节点的节点集: 1.child 选取当前节点的所有子元素 2.parent 选取当前节点的父节点 3.descendant 选取当前节点的所有后 ...
- Masha and Bears(翻译+思维)
Description A family consisting of father bear, mother bear and son bear owns three cars. Father bea ...
- 王者荣耀交流协会 -- 第4次Scrum会议
Scrum master : 王磊 要求1 : 工作照片 照片由高远博同学拍摄 ,王露芝同学(外援)没有参加本次会议. 要求2 : 时间跨度:2017年10月16日 18:00 - 18:44 共计4 ...
- emmmmmm
211606342杨艺勇 211606379王熙航 单元测试 对每一个代码块进行测试,返回测试结果并和预期结果进行比对 对源代码进行相应的重构,以适应测试代码的调用,且不影响源代码的正常运行 通过与构 ...
- Alpha冲刺——第九天
Alpha第九天 听说 031502543 周龙荣(队长) 031502615 李家鹏 031502632 伍晨薇 031502637 张柽 031502639 郑秦 1.前言 任务分配是VV.ZQ. ...