意甲冠军:

对于数字n, 他询问是否有1~n置换 这种布置能够在产品上模每个前缀n 有可能0~n-1

解析:

通过观察1肯定要在首位,n一定要在最后

除4意外的合数都没有解

其它质数构造 a[i]=i*inv[i-1] , 这样用逆元把前面每一个数的影响都消除掉

C. Prefix Product Sequence
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Consider a sequence [a1, a2, ...
, an]. Define its prefix product sequence .

Now given n, find a permutation of [1, 2, ..., n],
such that its prefix product sequence is a permutation of [0, 1, ..., n - 1].

Input

The only input line contains an integer n (1 ≤ n ≤ 105).

Output

In the first output line, print "YES" if such sequence exists, or print "NO"
if no such sequence exists.

If any solution exists, you should output n more lines. i-th
line contains only an integer ai.
The elements of the sequence should be different positive integers no larger than n.

If there are multiple solutions, you are allowed to print any of them.

Sample test(s)
input
7
output
YES
1
4
3
6
5
2
7
input
6
output
NO
Note

For the second sample, there are no valid sequences.


/* ***********************************************
Author :CKboss
Created Time :2015年03月12日 星期四 19时58分14秒
File Name :CF487C.cpp
************************************************ */ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map> using namespace std; typedef long long int LL; const int maxn=100100; int n;
LL a[maxn],inv[maxn]; bool isprime(int x)
{
if(x==2||x==1) return true;
if(x%2==0) return false;
for(int i=3;i*i<=x;i+=2) if(x%i==0) return false;
return true; } void solve()
{
inv[1]=1LL;
for(int i=2;i<=n;i++) inv[i]=inv[n%i]*(n-n/i)%n;
a[1]=1LL; a[n]=n;
for(int i=2;i<n;i++) a[i]=(i*inv[i-1])%n;
for(int i=1;i<=n;i++) printf("%I64d\n",a[i]);
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); scanf("%d",&n);
if(n==4)
{
puts("YES"); puts("1"); puts("3"); puts("2"); puts("4");
return 0;
}
if(isprime(n)==false) puts("NO");
else
{
puts("YES");
solve();
} return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

Codeforces 487C. Prefix Product Sequence 逆+结构体的更多相关文章

  1. Codeforces.487C.Prefix Product Sequence(构造)

    题目链接 \(Description\) 对于一个序列\(a_i\),定义其前缀积序列为\(a_1\ \mathbb{mod}\ n,\ (a_1a_2)\ \mathbb{mod}\ n,...,( ...

  2. 487C Prefix Product Sequence

    传送门 题目大意 分析 因为n为质数所以i-1的逆元唯一 因此ai唯一 代码 #include<iostream> #include<cstdio> #include<c ...

  3. [CF 487C Prefix Product Sequence]

    题意 将1~n的正整数重排列,使得它的前缀积在模n下形成0~n-1的排列,构造解或说明无解.n≤1E5. 思考 小范围内搜索解,发现n=1,n=4和n为质数时有解. 不难发现,n一定会放在最后,否则会 ...

  4. codeforces 487C C. Prefix Product Sequence(构造+数论)

    题目链接: C. Prefix Product Sequence time limit per test 1 second memory limit per test 256 megabytes in ...

  5. cf487C Prefix Product Sequence

    Consider a sequence [a1, a2, ... , an]. Define its prefix product sequence . Now given n, find a per ...

  6. Prefix Product Sequence CodeForces - 487C (数论,构造)

    大意: 构造一个[1,2,...n]的排列, 使得前缀积模n为[0,1,...,n-1]的排列 这种构造都好巧妙啊, 大概翻一下官方题解好了 对于所有>=6的合数$n$, 有$(n-1)! \e ...

  7. Go语言中结构体的使用-第2部分OOP

    1 概述 结构体的基本语法请参见:Go语言中结构体的使用-第1部分结构体.结构体除了是一个复合数据之外,还用来做面向对象编程.Go 语言使用结构体和结构体成员来描述真实世界的实体和实体对应的各种属性. ...

  8. Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final) C. The Delivery Dilemma (贪心,结构体排序)

    题意:你要买\(n\)份午饭,你可以选择自己去买,或者叫外卖,每份午饭\(i\)自己去买需要消耗时间\(b_i\),叫外卖需要\(a_i\),外卖可以同时送,自己只能买完一份后回家再去买下一份,问最少 ...

  9. Codeforces Round #531 (Div. 3) B. Array K-Coloring (结构体排序)

    题意:给你\(n\)个数字,用\(k\)种颜色给他们涂色,要求每个数字都要涂,每种颜色都要用,相同的数字不能涂一样的颜色. 题解:用结构体读入每个数字和它的位置,然后用桶记录每个数字出现的次数,判断是 ...

随机推荐

  1. memcached 分布式聚类算法

    memcached 分布式集群,该决定必须书面开发商自己.和redis 由分布式server决定.上 memcached 有两个选项用于分布式.第一个是:模运算 另一种是:一致性hash 分布式算法. ...

  2. OpenCms创建网站的过程示意图——专用OpenCms人们刚开始学习

    很多人听说过OpenCms,我知道它的强大,只需下载并安装,最后,我们看到了久违OpenCms,我们看到了它的简单的界面,喜悦之后,但难免困惑.如何用这个东西,我如何用它来网站,从哪里开始,无从下手. ...

  3. cocos2dx的发展的例子2048(加入动画版)

    网上找了很多写作教程2048.只是不知道卡的移动动画,我写了一个完美的动画版少. 开发步骤: 1,一个设计CardSprite类. 2,设计主游戏场景GameScene,实现游戏逻辑,加入动画逻辑. ...

  4. UseCase事件描述叙事流规范

    文化/fasiondog 整理的用例需求编写规范.分享部分UseCase事件描述叙事流规范.其中.标准5~10.12来自哪里<编写有效用例>([美国] Alistair Cockburn ...

  5. Unity UGUI——开源

    开源许可证:MIT/X11 来源托管网站:BitBucket

  6. 基于最简单的FFmpeg采样读取内存读写:存储转

    ===================================================== 基于最简单的FFmpeg样品系列读写内存列表: 最简单的基于FFmpeg的内存读写的样例:内 ...

  7. UVa 11879 - Multiple of 17

    称号:计算一个数字是不17倍数. 说明:串,睑板. 简单的问题,直接推论可以是. 设定 n = 10a + d:(0 ≤ d ≤ 9) a - 5d = 51a - 5n,假设n被17整除,这个数必定 ...

  8. tomcat 重启进程

    查看端口: ps -aux | grep tomcat 发现并没有8080端口的Tomcat进程. 使用命令:netstat –apn 查看所有的进程和端口使用情况.发现下面的进程列表,其中最后一栏是 ...

  9. 请注意CSDN社区微通道,许多其他的精彩等着你

    CSDN社区微信公众号"程序人生"(微信ID:coder_life)来了,每天我们会将CSDN社区中大量的优质内容浓缩成1~3篇文章.推送到您的手机中,让您不管何时何地都能感受到知 ...

  10. 两个堆叠fragment,上层fragment响应于降低fragment的button点击事件补救措施

    加入onViewCreated的Touch事件监听, 以解决叠在一起的fragment上层响应下层的button点击事件解决方法 @Override public void onViewCreated ...