意甲冠军:

对于数字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. Qt学习一门:直接使用QT具

    今天,通过直接使用QT一些工具来编写命令行程序.你可以看到一种Qt更一般的用法. 内容很easy,输出电流日期. 首先,用一个QDate分类,可以使用QDate类的静态方法currentDate为了得 ...

  2. shell编程三大神器之awk

  3. 对于Hadoop的MapReduce编程makefile

    根据近期需要hadoop的MapReduce程序集成到一个大的应用C/C++书面框架.在需求make当自己主动MapReduce编译和打包的应用. 在这里,一个简单的WordCount1一个例子详细的 ...

  4. java基础---->Zip压缩的使用(转)

    java中提供了对压缩格式的数据流的读写.它们封装到现成的IO 类中,以提供压缩功能.下面我们开始java中压缩文件的使用. 目录导航: 关于压缩的简要说明 GZIP压缩文件的使用 ZIP压缩文件的使 ...

  5. Spring MVC helloWorld中遇到的问题及解决办法

    1.java.io.FileNotFoundException: Could not open ServletContext resource不能加载ServletContext的用法是配置到web. ...

  6. mysqldump: Couldn't execute 'show events': Cannot proceed because system tables used by Event Schedu

    最近将老版本的mysql 实例倒入 percona 5.5.30,使用的是线上的全备,结果将mysql 库下的表也倒入了,这下可悲剧了,备份报错. 没办法,将mysql库下的数据倒出来,清空,再倒入p ...

  7. SharePoint使用BCS开发你第一个应用程序(一)

    SharePoint使用BCS开发你第一个应用程序(一)         本系列教你使用BCS(Business Connectivity Service)创建OBA(Office business ...

  8. VMware装ubuntu 进不去图形界面, 卡在Installing VMware Tools

    1.按Ctrl +C结束,进入命令行 2.ubuntu login:_ 依次输入: 1)你的用户名:输入自己的! 2)你的密码:输入自己的! 3)获取root权限:sudo su 输密码 4)/etc ...

  9. [LeetCode257]Binary Tree Paths

    题目: Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree ...

  10. JSON小结

    在 JSON 中,“Object” 是什么呢? json.org 有很好的解释: 1 .An object is an unordered set of name/value pairs. 2.An ...