当前位置:网站首页>神奇快速幂
神奇快速幂
2022-07-07 21:53:00 【sophilex】
思路;
纯模拟肯定是送,有很多人都是打表找规律,找循环节然后过去的。
在网上看到一个秀翻我的思路:把一次传染过程看作乘法操作,操作对象为标记数组,那么经历了k次操作,也就是乘了k次,这就是一个变形的快速幂
那么只要按照快速幂敲一下就好了
整体复杂度大概是m^2*log(k),4e7的水平,理论上是能过的
but,时间还是卡的很死的(可能常数有点大),必须得把所有杂七杂八的优化全部加上去:快读,register,inline。。。
优化到极致了,才能过。。。(亲身体会)
虽然但是,这个思路确实是我第一次见,很优秀
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lowbit(x) x&(-x)
const int N=1500;
ll k;
int m,n;
inline ll read() {
register char ch;
while(!isdigit(ch=getchar()));
register ll x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return x;
}
bool mas[N],tp[N],ans[N];
inline void mul(bool a[],bool b[])
{
memset(tp,0,sizeof tp);
for(register int i=0;i<m;++i)
{
for(register int j=0;j<m;++j)
{
tp[i*j%m]|=a[i]&&b[j];
}
}
std::copy(&tp[0],&tp[m],a);
}
int main()
{//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
k=read();m=read();n=read();
for(register int i=1;i<=n;++i)
{
//a=read();
mas[read()]=1;
}
ans[1]=1;
while(k)
{
if(k&1) mul(ans,mas);
mul(mas,mas);
k>>=1;
}
for(register int i=0;i<m;++i) if(ans[i]) printf("%d ",i);
return 0;
}
边栏推荐
- [untitled]
- B_QuRT_User_Guide(36)
- 高效的S2B2C电商系统,是这样帮助电子材料企业提升应变能力的
- webflux - webclient Connect reset by peer Error
- SRM supplier cloud collaborative management platform solution for building materials industry to realize business application scalability and configuration
- [compilation principle] lexical analysis design and Implementation
- SAP HR 劳动合同信息 0016
- Right click the idea file to create new. There is no solution to create new servlet
- HDU 4747 mex "recommended collection"
- USB (XIV) 2022-04-12
猜你喜欢
Deep understanding of MySQL lock and transaction isolation level
【路径规划】使用垂距限值法与贝塞尔优化A星路径
Right click the idea file to create new. There is no solution to create new servlet
B / Qurt Utilisateur Guide (36)
How to change the formula picture in the paper directly into the formula in word
The file format and extension of XLS do not match
C inheritance and interface design polymorphism
KeePass realizes automatic input of web pages
SAP HR 社会工作经历 0023
Ora-02437 failed to verify the primary key violation
随机推荐
生鲜行业数字化采购管理系统:助力生鲜企业解决采购难题,全程线上化采购执行
Stringutils tool class
【汇总】看过的一些Panel与视频
As a new force, chenglian premium products was initially injected, and the shares of relevant listed companies rose 150% in response
【7.4】25. K 个一组翻转链表
Dependency injection
B_QuRT_User_Guide(36)
平衡二叉樹【AVL樹】——插入、删除
USB (XV) 2022-04-14
C method question 2
Dataguard 主备清理归档设置
JNI uses asan to check memory leaks
Arbre binaire équilibré [Arbre AVL] - Insérer et supprimer
Understand TCP's three handshakes and four waves with love
Benchmarking Detection Transfer Learning with Vision Transformers(2021-11)
Pycharm essential plug-in, change the background (self use, continuous update) | CSDN creation punch in
[stm32+esp8266 connect Tencent cloud IOT development platform 2] stm32+esp8266-01s connect Tencent cloud
数据库面试题+解析
Anxinco esp32-a1s development board is adapted to Baidu dueros routine to realize online voice function
Take you hand in hand to build feign with idea