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次都失败了,最后一次成功. 问:该密码箱最多有多少 ...
随机推荐
- python-全栈开发-前方高能-内置函数
python_day_14 13. 前方高能-内置函数 ⼀. 本节主要内容: 1. 内置函数 什么是内置函数? 就是python给你提供的. 拿来直接⽤的函数, 比如print., input等等. ...
- POJ-2018(二分)
//意是在一个数组里,寻找一段连续和,使其平均和最大,但是长度不能小于F, //首先可以看出是满足单调性的,但是怎么二分呢, //我们先枚举一个可能的数. //然后数组里的值全部减去这个值(结果会有正 ...
- android开发问题 Failed to pull selection 菜鸟记录
在eclipse中开发创建了一个sqlite数据库文件,为了查看数据库文件的内容,决定复制到PC上一看究竟,位置在data……里 当我点击ddms文件浏览里的pull a file from the ...
- [Algorithm] A* Search Algorithm Basic
A* is a best-first search, meaning that it solves problems by searching amoung all possible paths to ...
- 常用 php server
php编程中经常需要用到一些服务器的一些资料,我把常用的用高亮的方式贴出来,其余的放在后面.方便以后查阅 复制代码代码如下: $_SERVER['HTTP_ACCEPT_LANGUAGE']/ ...
- 将Python文件打包为exe文件,并在控制台运行之简易教程
第一步 在线安装 pyinstaller. 方法:打开win+ R,输入cmd,在命令行输入"pip install pyinstaller" 静等几分钟后即可安装成功. ...
- Python:print()函数的几个常用参数
1.参数sep:设置输出字符产之间的字符串.默认是空格 name='Tomwenxing' age=' job='student' print(name,age,job) print(name,age ...
- 模拟登入教务处(header)
import HTMLParser import urlparse import urllib import urllib2 import cookielib import string import ...
- Storm事务Topology的接口介绍
ITransactionalSpout 基本事务Topology的Spout接口,内含两部分接口:协调Spout接口以及消息发送Blot接口. TransactionalSpoutBatchExe ...
- MySQL 基于lvm2的备份实战演练 (快照备份)
前言: lvm2实现热备的原理是基于lvm2的快照功能,lvm2可以实现数据集不大的情况下的热备. 实战过程如下:这里的演示是在一台Mariadb服务器上进行创建快照,将快照中的文件scp到备份服务器 ...