HDU 4790 Just Random Math

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.