bzoj2277 [Poi2011]Strongbox
2277: [Poi2011]Strongbox
Time Limit: 60 Sec Memory Limit: 32 MB
Submit: 498 Solved: 218
[Submit][Status][Discuss]
Description
有一个密码箱,0到n-1中的某些整数是它的密码。
且满足,如果a和b都是它的密码,那么(a+b)%n也是它的密码(a,b可以相等)
某人试了k次密码,前k-1次都失败了,最后一次成功了。
问:该密码箱最多有多少不同的密码。
Input
第一行n,k
下面一行k个整数,表示每次试的密码
保证存在合法解
1<=k<=250000 k<=n<=10^14
Output
一行,表示结果
Sample Input
28 31 10 38 24
Sample Output
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll; ll n,k,a[],ans = n,cnt; bool check(ll x)
{
for (int i = ; i <= cnt; i++)
if (a[i] % x == )
return false;
return true;
} ll gcd(ll a,ll b)
{
if (!b)
return a;
return gcd(b,a % b);
} int main()
{
scanf("%lld%lld",&n,&k);
for (int i = ; i <= k; i++)
{
scanf("%lld",&a[i]);
a[i] = gcd(a[i],n);
}
sort(a + ,a + k);
for (int i = ; i < k; i++)
if (a[i] != a[i - ])
a[++cnt] = a[i];
for (ll i = ; i <= sqrt(a[k]); i++)
if (a[k] % i == )
{
if (check(i))
{
ans = n / i;
break;
}
else
if (check(a[k] / i))
ans = n / a[k] * i;
}
printf("%lld\n",ans); return ;
}
bzoj2277 [Poi2011]Strongbox的更多相关文章
- BZOJ2277[Poi2011]Strongbox——数论
题目描述 Byteasar is a famous safe-cracker, who renounced his criminal activity and got into testing and ...
- BZOJ2277 [Poi2011]Strongbox 【数论】
题目链接 BZOJ2277 题解 orz太难了 如果一个数\(x\)是密码,那么所有\((x,n)\)的倍数都是密码 如果两个数\(x,y\)是密码,那么所有\((x,y)\)的倍数都是密码 那么如果 ...
- bzoj 2277 [Poi2011]Strongbox 数论
2277: [Poi2011]Strongbox Time Limit: 60 Sec Memory Limit: 32 MBSubmit: 527 Solved: 231[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次都失败了,最后一次成功. 问:该密码箱最多有多少 ...
随机推荐
- Linux在线安装pip和numpy
最近写Python需要用到numpy包 运行pip install numpy就会自动安装 一.因此需要先安装pip 1.如果安装的是Python>=2.7.9或者Python>=3.4, ...
- spring-bean(三)
配置方式:通过工厂方法配置bean,通过FactoryBean配置bean 配置形式:基于注解的方式 组件扫描 泛型依赖注入 静态工厂方法 /** * 静态工厂方法:直接调用某一个类的静态方法就可以返 ...
- hihocoder1718 最长一次上升子序列
思路: 对于每个i,分别求1~i和i+1~N两部分的最长下降子序列“拼”起来,最终取最大长度即可.学习了如何使用BIT把LIS问题O(N2)算法优化为O(Nlog(N))的算法. https://ww ...
- P1967 货车运输 未完成
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #inclu ...
- Ant题解
Description: 一根长度为L厘米的木棒上有N只蚂蚁,每只蚂蚁要么向左走,要么向右走,速度为1厘米/秒.当两只蚂蚁相撞时,他们会同时掉头(掉头时间不计)给出每只蚂蚁距离木棒左端的距离,问多少秒 ...
- CCF|中间数|Java
import java.util.*; public class tyt { public static void main(String[] args) { Scanner in = new Sca ...
- iOS 播放本地,网络视频
/** * 创建媒体播放控制器MPMoviePlayerControlle 可以控制尺寸 * * @return 媒体播放控制器 */ -(MPMoviePlayerController *)mo ...
- windows系统下查看或删除自己电脑的共享文件以及文件夹
(1)查看所有共享 net share (2)删除指定共享 例如:删除C盘共享 net share C$ /delete net share 共享名 /delete (/del)
- CCS3超长文字显示省略号的方法
需求:当文本长度溢出包含元素时以省略号结尾 CSS3实现方法: #MyDIV{overflow:hidden;text-overflow:ellipsis;} 示例:<!DOCTYPE html ...
- Dreamoon and MRT(二元枚举)
题目 数轴上有M个点a1.a2....am,另有一个数列p1.p2....pn,(1 ≤ pii ≤ M). 给定d1.d2....dn,对所有的 i (1 ≤ i ≤ n),已知 |api+1 - ...