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. CSS 实现隐藏滚动条同时又可以滚动(转)

    CSS 实现隐藏滚动条同时又可以滚动 移动端页面为了更接近原生的体验,是否可以隐藏滚动条,同时又保证页面可以滚动? 使用 overflow:hidden 隐藏滚动条,但存在的问题是:页面或元素失去了滚 ...

  2. APP埋点:页面统计与事件统计该如何入手?

    我们平时所说的埋点,可以大致分为两部分,一部分是统计APP页面访问情况,即页面统计:另外一部分是统计APP内的操作行为,及自定义事件统计. 一.页面统计 页面统计,可以统计应用内各个页面的访问次数(P ...

  3. 前端读取Excel报表文件 js-xlsx

    1.http://www.cnblogs.com/imwtr/p/6001480.html (前端读取Excel报表文件) 2.https://github.com/SheetJS/js-xlsx

  4. Ant Design

    https://ant.design/components/form-cn/    (Ant Design of React 中文网) 1.Ant Design of react (相关资料) htt ...

  5. Sturts2 三种开发模式 (转)

    1.实现与 Servlet API的交互struts2中提供了Map类型的request.session与application,可以从ActionContext对象中获得.ActionContext ...

  6. 剑指offer--27.包含min函数的栈

    时间限制:1秒 空间限制:32768K 热度指数:252822 本题知识点: 栈 算法知识视频讲解 题目描述 定义栈的数据结构,请在该类型中实现一个能够得到栈中所含最小元素的min函数(时间复杂度应为 ...

  7. Django --- celery异步任务与RabbitMQ模块

    一 RabbitMQ 和 celery 1 celery Celery 是一个 基于python开发的分布式异步消息任务队列,通过它可以轻松的实现任务的异步处理, 如果你的业务场景中需要用到异步任务, ...

  8. android源码下载以及编译自己的ROM

    android源码下载以及编译自己的ROM 最近发现kernel.org被墙了,为什么这种网站也能被墙了? 要想下载源码的话,只能绕过去了.下面是我从网上搜索到的一些下载方法: =========== ...

  9. js中的函参(arguments)

    函参,顾名思义,就是函数的参数,一般我们的js函数这么写: function sum(a,b){ console.log(a+b); } 不难看出,这实现了两个数的相加,比如sum(1,2),打印结果 ...

  10. POSIX线程同步

    在posix编程中,如果在不同的线程中几乎同一时间操作同一个变量的时候,就会出现不同步. 如何解决这样的问题,这里需要用到互斥量,互斥锁的概念.请看UNIX环境高级编程P299页 #include & ...