[luoguP3599]Koishi Loves Construction
来源:互联网 发布:知乎健身的变化女生 编辑:程序博客网 时间:2024/05/21 09:29
题目描述
Koishi决定走出幻想乡成为数学大师!
Flandre听说她数学学的很好,就给Koishi出了这样一道构造题:
Task1:试判断能否构造并构造一个长度为n的的排列,满足其n个前缀和在模n的意义下互不相同
Taks2:试判断能否构造并构造一个长度为n的的排列,满足其n个前缀积在模n的意义下互不相同
按照套路,Koishi假装自己根本不会捉,就来找你帮忙辣。
问题一
容易知道n为大于1的奇数无解。
因为此时和为n的倍数所以第n项必须放n。
而不在第一项放n会使得存在两项相同,从而判断无解。
n为1特判掉。
考虑n为偶数如何构造。
可以考虑构造前缀和数组再倒推。
前缀和数组是0 1 n-1 2 n-2 3 n-3……n/2
容易证明减出来互不相同,这里略去。
问题二
容易知道n为大于4的合数无解。
因为n!肯定是n的倍数所以第n项必须放n。
假如n为合数能拆出n=pq
当p小于q时,显然(n-1)!含有p与q模n会为0。
当p等于q时,如果n大于4,就有
n等于4和1特判掉,然后考虑n为质数如何构造。
可以考虑构造前缀积数组再倒推。
前缀积数组是1 2 3 4 5 6……n
容易证明除出来互不相同,这里略去。
#include<cstdio>#include<algorithm>#include<cmath>#define fo(i,a,b) for(i=a;i<=b;i++)using namespace std;typedef long long ll;const int maxn=100000+10;int a[maxn],b[maxn];int i,j,k,l,t,n,m,ca,czy;int read(){ int x=0,f=1; char ch=getchar(); while (ch<'0'||ch>'9'){ if (ch=='-') f=-1; ch=getchar(); } while (ch>='0'&&ch<='9'){ x=x*10+ch-'0'; ch=getchar(); } return x*f;}void solve1(){ while (ca--){ n=read(); if (n%2==1){ if (n==1) printf("2 1\n"); else printf("0\n"); continue; } b[1]=0; fo(i,1,n/2){ b[i*2]=i; b[i*2+1]=n-i; } a[1]=n; fo(i,2,n) a[i]=((b[i]-b[i-1])%n+n)%n; printf("2 "); fo(i,1,n) printf("%d ",a[i]); printf("\n"); }}int quicksortmi(int x,int y){ if (!y) return 1; int t=quicksortmi(x,y/2); t=(ll)t*t%n; if (y%2) t=(ll)t*x%n; return t;}bool pd(int n){ int i; fo(i,2,floor(sqrt(n))) if (n%i==0) return 1; return 0;}void solve2(){ while (ca--){ n=read(); if (n==1) printf("2 1\n"); else if (n==2) printf("2 1 2\n"); else if (n==4) printf("2 1 3 2 4\n"); else{ if (pd(n)) printf("0\n"); else{ a[1]=1; fo(i,2,n-1) a[i]=(ll)(i-1)*quicksortmi(i,n-2)%n; a[n]=n; printf("2 "); fo(i,1,n) printf("%d ",a[i]); printf("\n"); } } }}int main(){ czy=read();ca=read(); if (czy==1) solve1(); else solve2();}
0 0
- [luoguP3599]Koishi Loves Construction
- [luoguP3598]Koishi Loves Number Theory
- #204. Koishi Loves Number Theory
- #203. Koishi Loves Dynamic Programming
- 洛谷 P3708 koishi的数学题
- 【洛谷P3708】koishi的数学题
- 洛谷 P3708 koishi的数学题
- 洛谷 P3708 koishi的数学题
- Managing Construction
- Tree Construction
- Road Construction
- Under Construction
- multiviews construction
- uva10720Graph Construction
- construction equipme
- default construction
- hdu3516Tree Construction
- Elegant Construction
- leecode 解题总结:114. Flatten Binary Tree to Linked List
- 用服务器日志监控软件、服务器日志分析工具软件教你如何查看服务器日志?
- 完美实现table带边框效果边框
- java线程同步volatile与synchronized(二)
- 找出值最大的行号和列号
- [luoguP3599]Koishi Loves Construction
- HiveQL:视图
- NumberUtils、ArrayUtils和RandomUtils工具类用法
- equals()、hashCode()方法
- TK联发科MTK8735 核心板4G 全网通4核64位 物联网方案LTE模块 MTK 3G/4G行业设备解决方案
- Xcode如何编写C++
- JDBC中日期时间的处理技巧
- 欢迎使用CSDN-markdown编辑器
- Mbed在自己的stm32系列平台移植适配(二)