<PREV Problem:
NEXT>
Solved by 93 users: ...
UserDateAttemptTimeCMSC
fetetriste16 jul 2009C++500.16169 
fetetriste16 jul 2009C++400.10176 
Romka17 jun 2008FPC302.04193 
blackmath14 jul 2008C++100.38197 
Puella12 mar 2009C++100.28203 
Abzal_ktl29 jun 2008Kylix501.98203 
ignat02 jun 2008C++300.22206 
tttttt01 jun 2012C++600.11215 
Philip_PV06 jul 2008C++1500.97217 
Lukasz16a27 jun 2008C++300.51218 
ignat02 jun 2008C++200.22221 
Philip_PV06 jul 2008C++1400.97221 
Chmeli_BSU24 jul 2008C++100.24223 
Languages
C++
74
Kylix
9
Java
5
FPC
4
C
1
 > 
 > 
 > 
 > 
 > 
 > 
 > 
 > 
 > 
 > 

Catalan numbers

Time limit = 3 second(s)

C(N) — Catalan number.

See Wikipedia Article "Catalan numbers" .

Find C(N) % K (operator % stands for residual).

Input. One line with N and K.

1 ≤ N ≤ 500 000, 1 ≤ K ≤ 2 000 000 000.

Output. C(N) % K.

Input#1
3 8		
Output#1
5

Input#2
1 352745736	
Output#2
1

Input#3
2 7344		
Output#3
2

Input#4
10000 1024
Output#4
480

Input#5
23 22	
Output#5
6

Author:
Artem Voroztsov -- statement and tests, Vyacheslav Bykov -- solution.

<PREV | Problem set | Search related messages | NEXT>


© acm.mipt DevGroup
The page was generated in 220ms

SW soft NIX
ID = 3.228.220.31