Sequence - URAL 1528 水题
2014-07-23 18:28
525 查看
1528. Sequence
Time limit: 3.0 secondMemory limit: 64 MB
You are given a recurrent formula for a sequence f:
f(n) = 1 + f(1)g(1) + f(2)g(2) + … + f(n−1)g(n−1),
where g is also a recurrent sequence given by formula
g(n) = 1 + 2g(1) + 2g(2) + 2g(3) + … + 2g(n−1) − g(n−1)g(n−1).
It is known that f(1) = 1, g(1) = 1. Your task is to find f(n) mod p.
Input
The input consists of several cases. Each case contains two numbers on a single line. These numbers are n (1 ≤ n ≤ 10000) and p (2 ≤ p ≤ 2·109).The input is terminated by the case with n = p = 0 which should not be processed. The number of cases in the input does not exceed 5000.
Output
Output for each case the answer to the task on a separate line.Sample
input | output |
---|---|
1 2 2 11 0 0 | 1 2 |
AC代码如下:
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> typedef long long ll; using namespace std; ll f[10010],mod; int main() { int n,i,j,k; f[1]=1; while(~scanf("%d%I64d",&n,&mod) && n) { for(i=2;i<=n;i++) f[i]=(f[i-1]*i)%mod; printf("%I64d\n",f ); } }
相关文章推荐
- URAL 1528 Sequence
- URAL 1528 Sequence
- URAL 1081 Binary Lexicographic Sequence (递推 + 递归)
- ural Brackets Sequence (dp)
- URAL 1901 Space Elevators (苦逼水题,2级)
- 2081 Recaman's Sequence 水题报告
- URAL 1001 Reverse Root(水题?)
- URAL 1880 Psych Up's Eigenvalues multiset水题
- URAL 1023 Buttons(巴什博弈水题)
- URAL 1183 Brackets Sequence DP 路径输出
- Ural 1558 - Periodical Numbers 写吐的水题...
- URAL 1901 Space Elevators (苦逼水题,2级)
- ural 1014【水题,不过有点阴人】
- Hungry Sequence(水题)
- ZOJ - 2421 Recaman's Sequence(打表水题)
- (HDU 5783)Divide the Sequence <思维水题> 多校训练5
- URAL 1136 Parliament 二叉树水题 BST后序遍历建树
- URAL 1991 The battle near the swamp 水题
- 个人排位赛--a 物理题,水题 URAL - 1939
- 【BZOJ2656】【Zjoi2012】数列(sequence) 水题,python水高精度