hihocoder1776 序列
思路:
考虑从左至右依次向每个位置放置数字,对于第i个位置,以i为结尾的i个前缀和模P是不能相等的(因为不存在和为P的倍数的子串),所以第i个位置只能放置P - i个不同的数字。则答案就是(P - 1) * (P - 2) * ... * (P - n)。
实现:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + ; int main()
{
ll n, P;
while (cin >> n >> P)
{
if (n > P - ) { cout << << endl; continue; }
ll ans = ;
for (ll i = P - ; i > P - - n; i--)
{
ans = ans * i % MOD;
}
cout << ans << endl;
}
return ;
}
hihocoder1776 序列的更多相关文章
- 【夯实PHP基础】UML序列图总结
原文地址 序列图主要用于展示对象之间交互的顺序. 序列图将交互关系表示为一个二维图.纵向是时间轴,时间沿竖线向下延伸.横向轴代表了在协作中各独立对象的类元角色.类元角色用生命线表示.当对象存在时,角色 ...
- Windows10-UWP中设备序列显示不同XAML的三种方式[3]
阅读目录: 概述 DeviceFamily-Type文件夹 DeviceFamily-Type扩展 InitializeComponent重载 结论 概述 Windows10-UWP(Universa ...
- 软件工程里的UML序列图的概念和总结
俗话说,自己写的代码,6个月后也是别人的代码……复习!复习!复习! 软件工程的一般开发过程:愿景分析.业务建模,需求分析,健壮性设计,关键设计,最终设计,实现…… 时序图也叫序列图(交互图),属于软件 ...
- python序列,字典备忘
初识python备忘: 序列:列表,字符串,元组len(d),d[id],del d[id],data in d函数:cmp(x,y),len(seq),list(seq)根据字符串创建列表,max( ...
- BZOJ 1251: 序列终结者 [splay]
1251: 序列终结者 Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 3778 Solved: 1583[Submit][Status][Discu ...
- 最长不下降序列nlogn算法
显然n方算法在比赛中是没有什么用的(不会这么容易就过的),所以nlogn的算法尤为重要. 分析: 开2个数组,一个a记原数,f[k]表示长度为f的不下降子序列末尾元素的最小值,tot表示当前已知的最长 ...
- [LeetCode] Sequence Reconstruction 序列重建
Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- [LeetCode] Repeated DNA Sequences 求重复的DNA序列
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
随机推荐
- IDEA 设置背景颜色及字号
intellij IDEA 设置背景颜色 File--> Settings 2. Appearance & Behavior --> Appearance 设置边框背景颜色 3 ...
- maven目录结构
groupId的值是项目的包名 artifactId的值是模块名,建议使用项目名
- windows兼容dirent.h
尝试在windows下跑KCF算法,创建工程编译后出现: Error 4 error C1083: Cannot open include file: 'dirent.h': No such file ...
- libvirt监控
- web面试常见问题
1事件继承 function ClassA(sColor) { this.color = sColor; this.sayColor = function () { al ...
- 02-安装JDK - Java快速入门
jdk安装的版本
- FTP服务基础
网络文件共享 本章内容 FTP服务 NFS服务 SAMBA服务 DAS.NAS.SAN(文件) DAS:开放系统的直连式存储(Direct-Attached Storage) 磁盘连接到本机的电脑上, ...
- CodeForces - 767C Garland 树的遍历
C. Garland time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- win7 mongod不是内部命令
1.下载MongoDB 1.1 MongoDB下载 1.2 选择Server下面的 Community 2.安装MongoDB 2.1 注意事项:一直下一步就行了,但是遇到下面这个界面,注意一定要去掉 ...
- NSString 是否存在空格
NSString *_string = [NSString stringWithFormat:@"123 456"]; NSRange _range = [_string rang ...