Link:
pid=4790 ">http://acm.hdu.edu.cn/showproblem.php?pid=4790
Meaning: From "a." B "Randomly finds a number x, from" C. D "Randomly finds a number Y. Give the P. M, assuming (X+y)%p==m is successful, ask the probability of success is how much.
Idea: "A." B "in the number of consecutive p. Number of consecutive p in "C,d". The combination of this 2*p number can find a successful combination of P species (detailed), so find "a." B "in the number of P-loops x1," c,d "in the number of P-loops Y1, then they constitute a successful combination of p*x1*y1.
Then the problem of dealing with the boundary, first X or y in the number of boundaries must not exceed the number of p-1, set x2,y2 respectively, this x2. The number of Y2 must be able to find a corresponding successful combination in each of the corresponding loops. So we have to x2*y1+y2*x1 a few more successful combinations.
Finally, we will find the corresponding number in this x2,y2 number. Because of the requirement for x2+y2≡m (mod p), so (m-x2) ≡y2 (mod p), and then find their overlapping parts can be.
Code:
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <map># Include <cstdlib> #include <queue> #include <stack> #include <vector> #include <ctype.h># Include <algorithm> #include <string> #include <set> #define PI acos ( -1.0) #define MAXN 10005#define INF 0x7fffffff#define EPS 1e-8typedef long long ll;typedef unsigned long long ull;using namespace Std;int main () {int T; scanf ("%d", &t); for (int ii=1; ii<=t; ii++) {LL a,b,c,d,p,m; scanf ("%i64d%i64d%i64d%i64d%i64d%i64d", &a,&b,&c,&d,&p,&m); LL x=b-a+1,y=d-c+1; LL xx= (b-a+1)/p; LL yy= (d-c+1)/p; LL xxx=x-xx*p; LL yyy=y-yy*p; LL t=xx*yy*p; LL Fm=x*y; T+=xxx*yy; T+=yyy*xx; if (xxx!=0&&yyy!=0) {LL head=a%p; LL tail=b%p; LL head1= ((m-tail)%p+p)%p; LL tail1= ((m-head)%p+p)%p LL head2=c%p; LL tail2=d%p; cout<
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
HDU 4790 Just Random Math