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

  1. 化简之后F(i)=i+3;因为L,R很大,但是P很小,只要R-L+1>=P
  2. 则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的更多相关文章

  1. 第12届北师大校赛热身赛第二场 C. 组合数

    题目链接:http://www.bnuoj.com/bnuoj/contest_show.php?cid=3570#problem/43573 C. 组合数 Time Limit: 1000ms Ca ...

  2. 第12届北师大校赛热身赛第二场 A.不和谐的长难句1

    题目链接:http://www.bnuoj.com/bnuoj/problem_show.php? pid=17121 2014-04-25 22:59:49 不和谐的长难句1 Time Limit: ...

  3. 第12届北师大校赛热身赛第二场 B起床的烦恼

    题目链接:http://www.bnuoj.com/bnuoj/contest_show.php? cid=3570#problem/43572 题目大意: Nono从一開始数数,他每数一个数时会计算 ...

  4. 【魔改】莫队算法+组合数公式 杭电多校赛4 Problem B. Harvest of Apples

    http://acm.hdu.edu.cn/showproblem.php?pid=6333 莫队算法是一个离线区间分块瞎搞算法,只要满足:1.离线  2.可以O(1)从区间(L,R)更新到(L±1, ...

  5. 校赛热身 Problem B. Matrix Fast Power

    找循环节,肯定在40项以内,不会证明. #include <iostream> #include <cstring> #include <string> #incl ...

  6. 校赛热身 Problem C. Sometimes Naive (状压dp)

    题解: 列举每一种3的倍数的组合,开始先求出3条边的可行解,则 六条边的可行解可以由两个三条边得来. 详见代码解析 #include<bits/stdc++.h> using namesp ...

  7. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  8. SCNU省选校赛第二场B题题解

    今晚的校赛又告一段落啦,终于"开斋"了! AC了两题,还算是满意的,英语还是硬伤. 来看题目吧! B. Array time limit per test 2 seconds me ...

  9. 2014上半年acm总结(1)(入门+校赛)

    大一下学期才开始了acm,不得不说有一点迟,但是acm确实使我的生活充实了很多,,不至于像以前一样经常没事干=  = 上学期的颓废使我的c语言学的渣的一笔..靠考前突击才基本掌握了语法 寒假突然醒悟, ...

随机推荐

  1. Shell 运算符 if

    Shell 支持多种运算符,包括: 算术运算符 原生bash不支持简单的数学运算,可以使用 expr,let 关系运算符 布尔运算符 字符串运算符 文件运算符 算术运算符 包括加减乘除,取余(%).赋 ...

  2. redis:php-redis中有序集合 zset的使用

    ZSET(stored set) 和 set 一样是字符串的集合,不同的是每个元素都会关联一个 double 类型的 score .实现使用的是 skip list 和 hash table , sk ...

  3. git一个系列教程

    https://git-scm.com/book/zh/v1/%E8%B5%B7%E6%AD%A5-%E5%85%B3%E4%BA%8E%E7%89%88%E6%9C%AC%E6%8E%A7%E5%8 ...

  4. vue.js 1.0中用v-for遍历出的li中的@click事件在移动端无效

    在vue.js使用v-for遍历出的li中的@click事件在移动端无效,在网页端可以执行,代码如下 <template> <div class="rating-secti ...

  5. Spring 在xml配置里配置事务

    事先准备:配置数据源对象用<bean>实例化各个业务对象. 1.配置事务管理器. <bean id="transactionManager" class=&quo ...

  6. Arcgis Add-In开发入门实例

    作为一个本科侧重于应用,工作之后却做了开发的程序员来说,做GIS,开发应该是一门必修课,只是,苦于各种原因吧,做GIS应用的人会开发的很少,做GIS开发的大部分都是计算机出身,痛心疾首啊-- 不好意思 ...

  7. ng 变量和常量服务

    <!DOCTYPE html> <html ng-app="myApp"> <head lang="en"> <met ...

  8. HihoCoder1622 : 有趣的子区间(预处理+组合数)

    有趣的子区间 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 如果一个区间[a, b]内恰好包含偶数个回文整数,我们就称[a, b]是有趣的区间. 例如[9, 12]包含 ...

  9. Django之mysql表单操作

    在Django之ORM模型中总结过django下mysql表的创建操作,接下来总结mysql表记录操作,包括表记录的增.删.改.查. 1. 添加表记录 class UserInfo(models.Mo ...

  10. Yet another A + B

    time limit per test 0.25 s memory limit per test 64 MB input standard input output standard output Y ...