校赛热身赛 Problem D. Unsolved Mystery

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=1;i<=y;i++)
    {
        cout<<"Case #"<<i<<": ";
        long long r,l,p;
        cin>>l>>r>>p;
        long long s;
        if(p>=l+3&&p<=r+3) cout<<0<<endl;
        else
        {
            l+=3;
            r+=3;
            l=l%p;
            long long c=r-l+1;
            if(c+l-1>=p) cout<<0<<endl;
            else
            {
                for(long long i=l;i<=c+l-1;i++)
                {
                    s=(s*i)%p;
                }
            }
        }
        cout<<s<<endl;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/caiyishuai/p/13271116.html