【题解】P3599 Koishi Loves Construction
【题解】P3599 Koishi Loves Construction
\(\mod n\) 考虑如何构造,发现\(n\)一定在第一位,不然不行。\(n\)一定是偶数或者是\(1\),不然 \(n|\frac{n(n+1)}{2}\)则最后一项一定会和第一项相同。考虑让他们的前缀和变成这样子的数列\(\left[1,2,3,etc... \right]\) ,那么我们构造\(\left[n,1,n-2,3,n-4\right]\)就好了。
考虑构造第二问,\(\left[a_1,a_2,a_3,a_4,ect...\right]\)的前缀积相同,我们知道乘法逆元$a^{-1} \times a \equiv 1 \mod n \(,那么我们只要把每个数都乘上前那个数的乘法逆元,这样每个位置的前缀积都等于本身\)a_i \mod n$了。
#include<bits/stdc++.h>
#define RP(t,a,b) for(register ll (t)=(a),edd_=(b);t<=edd_;++t)
#define DRP(t,a,b) for(register int (t)=(a),edd_=(b);t>=edd_;--t)
#define ERP(t,a) for(int t=head[a];t;t=e[t].nx)
#define Max(a,b) ((a)<(b)?(b):(a))
#define Min(a,b) ((a)<(b)?(a):(b))
#define pushup(x) seg[(x)]=seg[(x)<<1]+seg[(x)<<1|1]
#define midd register int mid=(l+r)>>1
#define chek if(R<l||r<L)return
#define TMP template<class ccf>
#define rgt L,R,mid,r,pos<<1|1
#define lef L,R,l,mid,pos<<1
#define all 1,n,1
using namespace std;typedef long long ll;
TMP inline ccf qr(ccf k){
char c=getchar();
ccf x=0;
int q=1;
while(c<48||c>57)q=c==45?-1:q,c=getchar();
while(c>=48&&c<=57)x=x*10+c-48,c=getchar();
return q==-1?-x:x;
}
int X,T;ll yyb;
inline bool isp(int YYB){
for(int psj=2;psj*psj<=YYB;psj++)
if(!(YYB%psj))
return 0;
return 1;
}
const int maxn=1e5+15;
ll data[maxn];
int main(){
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
#endif
X=qr(1);
T=qr(1);
if(X==1){
while(T--){
yyb=qr(1);
int psj=2;
if(yyb%psj&&yyb!=1){
puts("0 ");
continue;
}else cout<<2<<' ';
cout<<yyb<<' ';
RP(t,1,yyb-1)
cout<<((t&1)?yyb-t:t)<<' ';
puts("");
}
}
else{
while(T--){
yyb=qr(1);
if(yyb!=1&&yyb!=4&&!isp(yyb)){
puts("0 ");
continue;
}
else
cout<<2<<' ';
if(yyb==1){
puts("1 ");
continue;
}
if(yyb==4){
puts("1 3 2 4 ");
continue;
}
data[1]=1;
ll p=yyb;
RP(t,2,yyb)
(data[t]=(ll)(p-p/t)*data[p%t]%p);
cout<<1<<' ';
RP(t,2,yyb-1)
cout<<t*data[t-1]%yyb<<' ';
cout<<yyb<<' ';
puts("");
memset(data,0,sizeof data);
}
}
return 0;
}
【题解】P3599 Koishi Loves Construction的更多相关文章
- P3599 Koishi Loves Construction——构造题
题目 Task1:试判断能否构造并构造一个长度 $n$ 的 $1...n$ 的排列,满足其 $n$ 个前缀和在模 $n$ 的意义下互不相同 Task2:试判断能否构造并构造一个长度 $n$ 的 $1. ...
- C 洛谷 P3599 Koishi Loves Construction [构造 打表观察]
题目描述 Koishi决定走出幻想乡成为数学大师! Flandre听说她数学学的很好,就给Koishi出了这样一道构造题: Task1:试判断能否构造并构造一个长度为的的排列,满足其个前缀和在模的意义 ...
- 洛谷P3599 Koishi Loves Construction 构造
正解:构造 解题报告: 传送门! 这题俩问嘛,就分成两个问题港QwQ 就按顺序趴,先港第一问QwQ 首先要发现,n在膜n意义下就是0嘛 那作为前缀和的话显然它就只能放在第一个 然后再想下,发现,如果n ...
- 题解-Koishi Loves Construction
题解-Koishi Loves Construction 前缀知识 质数 逆元 暴搜 Koishi Loves Construction 给定 \(X\),\(T\) 组测试数据,每次给一个 \(n\ ...
- 【Luogu3602】Koishi Loves Segments(贪心)
[Luogu3602]Koishi Loves Segments(贪心) 题面 洛谷 题解 离散区间之后把所有的线段挂在左端点上,从左往右扫一遍. 对于当前点的限制如果不满足显然会删掉右端点最靠右的那 ...
- 【题解】DZY Loves Chinese
[题解]DZY Loves Chinese II 不吐槽这题面了... 考虑如何维护图的连通性,如果把图的变成一颗的\(dfs\)生成树,那么如果把一个节点的父边和他接下来所有的返祖边删除,那么我们就 ...
- 题解-ARC058D Iroha Loves Strings
题面 ARC058D Iroha Loves Strings 给定 \(n\) 个字符串,从中选出若干个按给出顺序连接起来,总长等于 \(m\),求字典序最小的,保证有解. 数据范围:\(1\le n ...
- E 洛谷 P3598 Koishi Loves Number Theory[数论]
题目描述 Koishi十分喜欢数论. 她的朋友Flandre为了检测她和数论是不是真爱,给了她一个问题. 已知 给定和个数,求对取模. 按照套路,呆萌的Koishi当然假装不会做了,于是她来向你请教这 ...
- D 洛谷 P3602 Koishi Loves Segments [贪心 树状数组+堆]
题目描述 Koishi喜欢线段. 她的条线段都能表示成数轴上的某个闭区间.Koishi喜欢在把所有线段都放在数轴上,然后数出某些点被多少线段覆盖了. Flandre看她和线段玩得很起开心,就抛给她一个 ...
随机推荐
- MariaDB主从复制、主主复制
1.部署 10.0.0.21 MariaDB-21 10.0.0.22 MariaDB-22 cat /etc/yum.repos.d/mariadb.repo [mariadb] name=Ma ...
- Linked List Cycle - LeetCode
Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using ext ...
- Google开源基于Tensorflow的NLP框架重大升级
http://weibo.com/ttarticle/p/show?id=2309404086117195475716
- Fresco对Listview等快速滑动时停止加载
Fresco中在listview之类的快速滑动时停止加载,滑动停止后恢复加载: 1.设置图片请求是否开启 // 暂停图片请求 public static void imagePause() { Fre ...
- mac 安装 redis
安装命令 brew install redis 开机启动redis命令 $ ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents 使用 ...
- Graphicmagick编译
为了需求给Graphicmagick加了几个支持,版本分别为mozjpeg2.1,bzip2-1.0.6,libpng-1.6.18,libwebp-0.4.3,mozjpeg-2.1,tiff-4. ...
- Java面向对象编程(二)
上一篇博文里总结了面向对象三大特性在Java中的体现.如今谈一谈Java中的抽象类,接口,内部类等特性. 一. 抽象类 public abstract class Shape { public int ...
- 微信小程序-使用腾讯Wxpage
微信小程序想要更快的速度吗? 满足你 https://github.com/tvfe/wxpage#-c%E5%AE%9A%E4%B9%89 使用超简单(导入wxpage.js,最后使用对象名:P): ...
- 【VBS】使用Visual Studio调试VBS程序
首先要确保机器上安装了Visual Stuido, 然后打开命令行窗口执行如下命令,会弹出是否使用Visual Studio进行调试的确认窗口. 点[是]进行调试. WScript.exe [vbs文 ...
- KVO(1)
#import "ViewController.h" @interface ViewController () @property(nonatomic, strong)UIButt ...