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. JNIjw05

    ZC: 这个代码,没有真正的运行测试 1.VC6(CPP)的DLL代码: #include<stdio.h> #include "jniZ_JNIjw05.h" #in ...

  2. HDFS集群启动的常见问题

    hdfs集群启动的常见问题 1.用浏览器访问namenode的50070端口,不正常,需要诊断问题出在哪里: a.在服务器的终端命令行使用jps查看相关进程 观察节点是否存活 b.如果已经知道了启动失 ...

  3. 阿里云上如何利用war包安装jenkins

    一. 前提条件:已安装jdk和tomcat 如何安装,请参考<如何在阿里云上部署war包到tomcat服务器> 二. 下载war包 下载地址:http://mirrors.jenkins- ...

  4. Mybatis输入和输出映射(#{}和${}的区别)

    #{}占位符                                                                                              ...

  5. 【Python】unicode' object is not callable

    在Python中,出现'unicode' object is not callable的错误一般是把字符串当做函数使用了.

  6. 【nyoj-1274】信道安全(SPFA)

    题目链接:http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=1274 题目描述 Alpha 机构有自己的一套网络系统进行信息传送.情报员 A 位于 ...

  7. day13作业

    #作业1猜年龄 , 可以让用户最多猜三次! # Auther:bing #!/usr/bin/env python age = 24 print("猜年龄") for i in r ...

  8. PostgreSQL upset解决在插入过程中重复数据冲突

    关于重复行问题: 在SQL Server中则可以自动排出重复行,不需要处理.在Oracle中经常遇到upsert语法,来排出冲突行.在PostgreSQL中,也需要手动排出重复行,否则会爆出错误,up ...

  9. TCP的保活定时器 转

    http://blog.csdn.net/zhangskd/article/details/44177475 TCP的Keepalive,目的在于看看对方有没有发生异常,如果有异常就及时关闭连接. 当 ...

  10. N位N进制里有多少个N

    32位二进制里有多少个1 https://blog.csdn.net/zhangsj1007/article/details/81411063 有这样一道计算机问题"32位二进制里面有多少个 ...