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次都失败了,最后一次成功. 问:该密码箱最多有多少 ...
随机推荐
- 【Windows定时关机】windows实现定时关机与取消
背景:本人昨晚本来打算将电脑设置为晚上12点 30定时关机,结果写成了:12:30,所以就在刚才,我正玩游戏的时候, 电脑弹出提示:“windows将在一分钟内关闭”,我刚开始一脸懵逼,后来打开昨天敲 ...
- tp框架-------验证码
验证码我们一般很常见,在注册或登录时,都可以用的到,下面我们就来看看它的代码和用法 加验证码是为了防止表单攻击的一种方式,为了我们的程序更加的安全 在tp框架中它自带了一个验证码的类,我们先来看一下 ...
- python--自定义模块
python模块说明:类似于函数式编程和面向过程编程,函数式编程则完成一个功能,其他代码用来调用即可,提供了代码的重用性和代码间的耦合.而对于一个复杂的功能来,可能需要多个函数才能完成(函数又可以在不 ...
- static和构造函数初始化顺序
abstract class demo{ public demo() {} protected void a() { System.out.println("I am parents!&qu ...
- Hexo+gitment
Gitment是一个基于GitHub问题的评论系统,可以在没有任何服务器端实现的前端使用. 演示页面 中文简介 特征 入门 方法 定制 关于安全 特征 GitHub登录 Markdown / GFM支 ...
- GitHub 多人协作开发 三种方式:
GitHub 多人协作开发 三种方式: 一.Fork 方式 网上介绍比较多的方式(比较大型的开源项目,比如cocos2d-x) 开发者 fork 自己生成一个独立的分支,跟主分支完全独立,pull代码 ...
- Redis 哨兵 Sentinel
Redis Sentinel:redis集群应用,分布式系统. 多个Sentinal进程之间通过 gossip 协议来接收主服务器是否下线的信息,通过 Raft 一致性协议来决定故障转移及转移服务 ...
- 对字符串进行base64加解密---基于python
本文介绍Python 2.7中的base64模块,该模块提供了基于rfc3548的Base16, 32, 64编解码的接口.官方文档,参考这里. 当前接口基于rfc3548的Base16/32/64编 ...
- Asphalting Roads(翻译!)
Description City X consists of n vertical and n horizontal infinite roads, forming n × n intersectio ...
- 团队backlog和燃尽图
首先我们的团队的任务是做一款一对一交流的软件,我们团队的backlog如下: 用电脑搭建一个服务器一对一平台 实现数据库和Android的链接 编写登陆,注册页面,和登陆成功界面,和登陆失败页面 实现 ...