当前位置:网站首页>神奇快速幂
神奇快速幂
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;
}边栏推荐
- PCB wiring rules of PCI Express interface
- Fibonacci number of dynamic programming
- SAP 内存参数调优过程
- 二叉排序树【BST】——创建、查找、删除、输出
- JNI uses asan to check memory leaks
- Anxinco EC series modules are connected to the multi protocol access products of onenet Internet of things open platform
- USB (XVI) 2022-04-28
- B_QuRT_User_Guide(40)
- Understand TCP's three handshakes and four waves with love
- 648. Word replacement
猜你喜欢
随机推荐
648. Word replacement
2022 certified surveyors are still at a loss when preparing for the exam? Teach you how to take the exam hand in hand?
数据分析系列 之3σ规则/依据拉依达准则来剔除异常值
Understand TCP's three handshakes and four waves with love
建筑建材行业SRM供应商云协同管理平台解决方案,实现业务应用可扩展可配置
IDEA 2021.3. X cracking
SAP 内存参数调优过程
Ora-02437 failed to verify the primary key violation
Fibonacci number of dynamic programming
Installing gradle
MySQL Index Optimization Practice I
Take you hand in hand to build Eureka server with idea
Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting
Class C design questions
Interface
Flash encryption process and implementation of esp32
进度播报|广州地铁七号线全线29台盾构机全部完成始发
ASP. Net query implementation
C number of words, plus ¥, longest word, average value
[compilation principle] lexical analysis design and Implementation









