当前位置:网站首页>神奇快速幂
神奇快速幂
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;
}
边栏推荐
- The file format and extension of XLS do not match
- First week of July
- USB (XV) 2022-04-14
- [STM32 + esp-12s connect Tencent cloud IOT development platform 1] creation of cloud platform and burning of at firmware
- [untitled]
- 城联优品作为新力量初注入,相关上市公司股价应声上涨150%
- Windows set redis to start automatically
- Deep understanding of MySQL lock and transaction isolation level
- Home appliance industry channel business collaboration system solution: help home appliance enterprises quickly realize the Internet of channels
- 电子设备行业智能供应链协同平台解决方案:解决低效, 赋能产业数字化升级
猜你喜欢
Anxin vb01 offline voice module access intelligent curtain guidance
Explain
Take you hand in hand to build Eureka client with idea
Extended tree (I) - graphic analysis and C language implementation
Arbre binaire équilibré [Arbre AVL] - Insérer et supprimer
Deep understanding of MySQL lock and transaction isolation level
What if once again forgets the login password of raspberry pie? And you don't have a monitor yet! Today, I would like to introduce a method
KeePass realizes automatic input of web pages
2022 certified surveyors are still at a loss when preparing for the exam? Teach you how to take the exam hand in hand?
Class C design questions
随机推荐
JNI uses asan to check memory leaks
ASP. Net core middleware request processing pipeline
Fibonacci number of dynamic programming
Possible SQL for Oracle table lookup information
UE4_ Use of ue5 blueprint command node (turn on / off screen response log publish full screen display)
2022 Season 6 perfect children's model Shaanxi finals came to a successful conclusion
SAP HR family member information
Explain
USB (XVII) 2022-04-15
Ora-02437 failed to verify the primary key violation
UE4_ Ue5 combined with Logitech handle (F710) use record
【7.4】25. K 个一组翻转链表
0-1背包问题
Live server usage
ASP. Net open web page
HDU 4747 mex "recommended collection"
B_QuRT_User_Guide(36)
B_ QuRT_ User_ Guide(37)
Markdown
生鲜行业数字化采购管理系统:助力生鲜企业解决采购难题,全程线上化采购执行