F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Tom and matrix

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1590    Accepted Submission(s): 485


Problem Description
Tom was on the way home from school. He saw a matrix in the sky. He found that if we numbered rows and columns of the matrix from 0, then,
${a}_{i,j}=C_{i}^{j}$

if i < j, ${a}_{i,j}=0$

Tom suddenly had an idea. He wanted to know the sum of the numbers in some rectangles. Tom needed to go home quickly, so he wouldn't solve this problem by himself. Now he wants you to help him.
Because the number may be very large, output the answer to the problem modulo a prime p.
 

Input
Multi test cases(about 8). Each case occupies only one line, contains five integers, ${x}_{1}¡¢{y}_{1}¡¢{x}_{2}¡¢{y}_{2}¡¢p.
{x}_{1}\leq {x}_{2}\leq {10}^{5},{y}_{1}\leq {y}_{2}\leq {10}^{5},2\leq p\leq {10}^{9}$.

You should calculate $\sum_{i={x}_{1}}^{{x}_{2}}\sum_{j={y}_{1}}^{{y}_{2}}{a}_{i,j}$ mod p
 

Output
For each case, print one line, the answer to the problem modulo p.
 

Sample Input
0 0 1 1 7 1 1 2 2 13 1 0 2 1 2
 

Sample Output
3 4 1
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 08:26:50, Gzip enabled