当前位置:网站首页>神奇快速幂
神奇快速幂
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;
}边栏推荐
- SAP HR 社会工作经历 0023
- Happy gathering time
- C语言学习
- UE4_ Ue5 combined with Logitech handle (F710) use record
- First week of July
- 高效的S2B2C电商系统,是这样帮助电子材料企业提升应变能力的
- The efficient s2b2c e-commerce system helps electronic material enterprises improve their adaptability in this way
- Mobile heterogeneous computing technology - GPU OpenCL programming (basic)
- USB (XIV) 2022-04-12
- C method question 2
猜你喜欢

The efficient s2b2c e-commerce system helps electronic material enterprises improve their adaptability in this way

Anxin vb01 offline voice module access intelligent curtain guidance

C inheritance and interface design polymorphism

Extended tree (I) - graphic analysis and C language implementation

Learn about scratch

MySQL Index Optimization Practice II

B_QuRT_User_Guide(38)

ESP at installation esp8266 and esp32 versions

B_ QuRT_ User_ Guide(38)

C # exchange number, judge to pass the exam
随机推荐
B_QuRT_User_Guide(39)
SQL database execution problems
Oracle string sorting
Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting
The for loop realizes 1-100 addition and eliminates the 4-digit tail number
生鲜行业数字化采购管理系统:助力生鲜企业解决采购难题,全程线上化采购执行
One of the anti climbing methods
Markdown
Live-Server使用
电子设备行业智能供应链协同平台解决方案:解决低效, 赋能产业数字化升级
C simple question 2
POJ2392 SpaceElevator [DP]
Open source hardware small project: anxinco esp-c3f control ws2812
[STM32 + esp-12s connect Tencent cloud IOT development platform 1] creation of cloud platform and burning of at firmware
B_ QuRT_ User_ Guide(39)
USB (XVII) 2022-04-15
数据库面试题+解析
ASP. Net open web page
2022 Season 6 perfect children's model Shaanxi finals came to a successful conclusion
[compilation principle] lexical analysis design and Implementation