Problem Description
When ?? was born, seven crows flew in and stopped beside him. In its childhood, ?? had been unfortunately fall into the sea. While it was dying, seven dolphins arched its body and sent it back to the shore. It is said that ?? used to surrounded by 7 candles when he faced a extremely difficult problem, and always solve it in seven minutes.
??
once wrote an autobiography, which mentioned something about himself.
In his book, it said seven is his favorite number and he thinks that a
number can be divisible by seven can bring him good luck. On the other
hand, ?? abhors some other prime numbers and thinks a number x divided
by pi which is one of these prime numbers with a given remainder ai will
bring him bad luck. In this case, many of his lucky numbers are
sullied because they can be divisible by 7 and also has a remainder of
ai when it is divided by the prime number pi.
Now give you a pair of x
and y, and N pairs of ai and pi, please find out how many numbers
between x and y can bring ?? good luck.
 
Input
On the first line there is an integer T(T≤20) representing the number of test cases.
Each test case starts with three integers three intergers n, x, y(0<=n<=15,0<x<y<1018) on a line where n is the number of pirmes.
Following
on n lines each contains two integers pi, ai where pi is the pirme and
?? abhors the numbers have a remainder of ai when they are divided by
pi.
It is guranteed that all the pi are distinct and pi!=7.
It is also guaranteed that p1*p2*…*pn<=1018 and 0<ai<pi<=105for every i∈(1…n).
 
Output
For each test case, first output "Case #x: ",x=1,2,3...., then output the correct answer on a line.
 
Sample Input
2
2 1 100
3 2
5 3
0 1 100
 
Sample Output
Case #1: 7
Case #2: 14
 
 
Hint

For Case 1: 7,21,42,49,70,84,91 are the seven numbers.
For Case2: 7,14,21,28,35,42,49,56,63,70,77,84,91,98 are the fourteen numbers.

 
说出来你可能不信,现在我要分析这个问题,我的博客从来就不会有代码,除了模板代码,,,,
题意: 不懂的看看。。。
就是X-Y 中的除以pi,余数不能为ai,求这样的所有的数,,,
现在我再想的是是不是把所有的整除7的都算出来, 然后|!A1∩!A2∩......∩!An|  = sum-奇数的+偶数的组合,,就是典型的容斥原理啊。。。
!A1使我们要求的东西,,不如让!A1代表除以pi,余数不为ai的东西,然后A1就是代表除以pi余数=ai的情况。
sum=y/7-(x-1)/7;   然后我们现在的重中之重就是求A1 这个东西怎么求,,,,我们注意到的东西就是0<pi<1e5;  但是我们发现了一个小小点的问题,,,
如果x%p[i]=y; 这个y在前面出现过那么的话 ,我们设前一个modp[i]=y的数为s,那么(x+7)%p[i]=(s+7)%p[i]; 所以我们可以在1e5的时间找到modp[i]=a[i]的数,因为这个东西是有周期的啊、、、然后发现我好想发现的没有用的东西,然后这个题还是做不出来,然后就是看别人的代码想到了中国剩余定理,然后这个题好像还有一个小的trick ,就是说乘的时候会爆longlong 这他妈的就尴尬啊。。。然后根据我的判断现在只能二分乘法了。。。。
 
 
 
 
 
 
 
 
 
 

Lucky7(容斥原理)的更多相关文章

  1. HDU 5768 Lucky7 容斥原理+中国剩余定理(互质)

    分析: 因为满足任意一组pi和ai,即可使一个“幸运数”被“污染”,我们可以想到通过容斥来处理这个问题.当我们选定了一系列pi和ai后,题意转化为求[x,y]中被7整除余0,且被这一系列pi除余ai的 ...

  2. HDU 5768:Lucky7(中国剩余定理 + 容斥原理)

    http://acm.hdu.edu.cn/showproblem.php?pid=5768 Lucky7 Problem Description   When ?? was born, seven ...

  3. 【中国剩余定理】【容斥原理】【快速乘法】【数论】HDU 5768 Lucky7

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5768 题目大意: T组数据,求L~R中满足:1.是7的倍数,2.对n个素数有 %pi!=ai  的数 ...

  4. HDU 5768 Lucky7 (容斥原理 + 中国剩余定理 + 状态压缩 + 带膜乘法)

    题意:……应该不用我说了,看起来就很容斥原理,很中国剩余定理…… 方法:因为题目中的n最大是15,使用状态压缩可以将所有的组合都举出来,然后再拆开成数组,进行中国剩余定理的运算,中国剩余定理能够求出同 ...

  5. HDU 5768 Lucky7(CRT+容斥原理)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5768 [题目大意] 求出一个区间内7的倍数中,对于每个ai取模不等于bi的数的个数. [题解] 首 ...

  6. HDU 5768 Lucky7 (中国剩余定理 + 容斥 + 快速乘法)

    Lucky7 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5768 Description When ?? was born, seven crow ...

  7. hdu-5768 Lucky7(容斥定理+中国剩余定理)

    题目链接: Lucky7 Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) Pr ...

  8. Lucky7(hdu5768)

    Lucky7 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  9. hdu4059 The Boss on Mars(差分+容斥原理)

    题意: 求小于n (1 ≤ n ≤ 10^8)的数中,与n互质的数的四次方和. 知识点: 差分: 一阶差分: 设  则    为一阶差分. 二阶差分: n阶差分:     且可推出    性质: 1. ...

随机推荐

  1. Linux文件编辑之sed命令

    文件编辑之sed命令 sed是一种流编辑器,它是文本处理中非常重要的工具,能够完美配合正则表达式使用,功能不同凡响.处理时,把当前处理的行存储在临时缓冲区中,称为模式空间 (pattern space ...

  2. Django 自定义模版标签和过滤器

    实现自定义过滤器 1. 创建register变量 在你的模块文件中,你必须首先创建一个全局register变量,它是用来注册你自定义标签和过滤器的, 你需要在你的python文件的开始处,插入几下代码 ...

  3. Python3基础 用list()查看filter()返回的对象

    镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.-------------------------------------- ...

  4. 升级R版本后,更新Package

    升级R版本后,若重新安装所有的package将非常麻烦,可以尝试运行一下程序: 1)在旧版本中的R中运行 #--run in the old version of R setwd("C:/T ...

  5. 封装bt轮播图淡入淡出效果样式

    <!--BT轮播图-->    <div data-ride="carousel" class="carousel slide carousel_inn ...

  6. Angular - - angular.bind、angular.bootstrap、angular.copy

    angular.bind 返回一个调用self的函数fn(self代表fn里的this).可以给fn提供参数args(*).这个功能也被称为局部操作,以区别功能. 格式:angular.bind(se ...

  7. Java语言Socket接口用法详解

    Socket接口用法详解   在Java中,基于TCP协议实现网络通信的类有两个,在客户端的Socket类和在服务器端的ServerSocket类,ServerSocket类的功能是建立一个Serve ...

  8. redhat+11g+rac 安装数据库软件时只有一个节点可选

    在安装数据库软件时,只能检测到一个节点 650) this.width=650;" title="捕获.JPG" src="http://s3.51cto.co ...

  9. 介绍一个开源的在线管理SQLServer的小工具--SQLEntMan

    近来有许多人问起SQL在线管理的问题,遂将以前用过的一个开源SQL 在线管理工具修改了一下,并分享. 看下效果图: 原项目的地址:http://sourceforge.net/projects/asp ...

  10. Express4.x安装

    1.首先肯定是要安装Node.JS npm install -g expressnpm install -g express-generator 运行express -V输出 4.9.0 2.创建一个 ...