校赛热身赛 Problem D. Unsolved Mystery
Problem D. Unsolved Mystery
The world famous mathematician Wang Hao published a paper recently in the journal “Nonsense”, there
is such a function in the paper:
F(x) = ⌊(√
(x + 3)√
(x + 2)x + 1)
(p
x + 3
p
x + 1)⌋ (x 1)
Now, Jelly has known L, R, and P, and he wants to know the results of the following formula:
(∏
R
i=L
F(i)
)
mod P
But Jelly is too busy, so he wants to ask you for help.
Input
The first line is an integer T, indicating the number of cases.
Each test case contains three integers L, R and P.
Output
For each test case, output one line containing “Case #x: y”, where x is the test case number (starting
from 1) and y is the answer.
Limits
1 T 20.
1 L R 1018
.
1 P 105
.
Example
standard input standard output
2
1 3 2
3 5 9
Case #1: 0
Case #2: 3
Note
For the first case, F(1) F(2) F(3) = 120, 120 mod 2 = 0.
For the second case, F(3) F(4) F(5) = 336, 336 mod 9 = 3
- 化简之后F(i)=i+3;因为L,R很大,但是P很小,只要R-L+1>=P
- 则L到R中一定存在P的倍数,因此输出0便可,否则循环求解。
#include <iostream>
#include <cstring>
#include<string>
#include <algorithm>
#include <queue>
using namespace std;
int main()
{
int t;
cin>>t;
for(int i=;i<=y;i++)
{
cout<<"Case #"<<i<<": ";
long long r,l,p;
cin>>l>>r>>p;
long long s;
if(p>=l+&&p<=r+) cout<<<<endl;
else
{
l+=;
r+=;
l=l%p;
long long c=r-l+;
if(c+l->=p) cout<<<<endl;
else
{
for(long long i=l;i<=c+l-;i++)
{
s=(s*i)%p;
}
}
}
cout<<s<<endl;
}
return ;
}
校赛热身赛 Problem D. Unsolved Mystery的更多相关文章
- 第12届北师大校赛热身赛第二场 C. 组合数
题目链接:http://www.bnuoj.com/bnuoj/contest_show.php?cid=3570#problem/43573 C. 组合数 Time Limit: 1000ms Ca ...
- 第12届北师大校赛热身赛第二场 A.不和谐的长难句1
题目链接:http://www.bnuoj.com/bnuoj/problem_show.php? pid=17121 2014-04-25 22:59:49 不和谐的长难句1 Time Limit: ...
- 第12届北师大校赛热身赛第二场 B起床的烦恼
题目链接:http://www.bnuoj.com/bnuoj/contest_show.php? cid=3570#problem/43572 题目大意: Nono从一開始数数,他每数一个数时会计算 ...
- 【魔改】莫队算法+组合数公式 杭电多校赛4 Problem B. Harvest of Apples
http://acm.hdu.edu.cn/showproblem.php?pid=6333 莫队算法是一个离线区间分块瞎搞算法,只要满足:1.离线 2.可以O(1)从区间(L,R)更新到(L±1, ...
- 校赛热身 Problem B. Matrix Fast Power
找循环节,肯定在40项以内,不会证明. #include <iostream> #include <cstring> #include <string> #incl ...
- 校赛热身 Problem C. Sometimes Naive (状压dp)
题解: 列举每一种3的倍数的组合,开始先求出3条边的可行解,则 六条边的可行解可以由两个三条边得来. 详见代码解析 #include<bits/stdc++.h> using namesp ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- SCNU省选校赛第二场B题题解
今晚的校赛又告一段落啦,终于"开斋"了! AC了两题,还算是满意的,英语还是硬伤. 来看题目吧! B. Array time limit per test 2 seconds me ...
- 2014上半年acm总结(1)(入门+校赛)
大一下学期才开始了acm,不得不说有一点迟,但是acm确实使我的生活充实了很多,,不至于像以前一样经常没事干= = 上学期的颓废使我的c语言学的渣的一笔..靠考前突击才基本掌握了语法 寒假突然醒悟, ...
随机推荐
- Dagger2 中的 Scope
Dagger2 中虽然概念挺多的,但是大部分花时间都能理清.包括看人家的分析,Debug 代码下去也能懂.但是对于 scope 的用法以及实现原理还是有点难理解的.主要的问题也像简书上的文章所说: 自 ...
- mysql数据库优化课程---10、mysql数据库分组聚合
mysql数据库优化课程---10.mysql数据库分组聚合 一.总结 一句话总结:select concat(class,' 班') 班级,concat(count(*),' 人') 人数 from ...
- ToggleButton开关状态按钮控件
ToggleButton开关状态按钮控件 一.简介 1. 2.ToggleButton类结构 父类是CompoundButton,引包的时候注意下 二.ToggleButton开关状态按钮控件使用方法 ...
- GO学习笔记:struct的匿名字段
我们上面介绍了如何定义一个struct,定义的时候是字段名与其类型一一对应,实际上Go支持只提供类型,而不写字段名的方式,也就是匿名字段,也称为嵌入字段. 当匿名字段是一个struct的时候,那么这个 ...
- Redis 应用笔记
模糊匹配 语法:KEYS pattern 说明:返回与指定模式相匹配的所用的keys. 该命令所支持的匹配模式如下: (1)?:用于匹配单个字符.例如,h?llo可以匹配hello.hallo和hxl ...
- Ajax技术基础
对于AJAX技术,感觉以前虽然用过但是对于AJAX没有一个清晰的认识,今天专门总结一下,希望掌握的更加牢固吧! 一,什么是AJAX? AJAX通常被叫做异步刷新技术,其实他也是可以同步的.主要都用于异 ...
- 遍历jsonArray和jsonObject
遍历jsonArray String str = "[{name:'a',value:'aa'},{name:'b',value:'bb'},{name:'c',value:'cc'}]&q ...
- Java 学习笔记(121208)
Java 修饰符 访问修饰符 修饰符 当前类 同一包内 子孙类 其他包 public Y Y Y Y protected Y Y Y N default Y Y N N private Y N N N ...
- Ceph与OpenStack整合(仅为云主机提供云盘功能)
1. Ceph与OpenStack整合(仅为云主机提供云盘功能) 创建: linhaifeng,最新修改: 大约1分钟以前 ceph ceph osd pool create volumes 128 ...
- LeetCode OJ:Reverse Linked List II(反转链表II)
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...