Sequence - URAL 1528 水题
来源:互联网 发布:国际足联排名算法 编辑:程序博客网 时间:2024/06/08 07:33
1528. Sequence
Time limit: 3.0 second
Memory limit: 64 MB
Memory 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
1 22 110 0
12
思路:其实就是n的阶乘取模。
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[n]); }}
0 0
- Sequence - URAL 1528 水题
- URAL 1528 Sequence
- URAL 1528Sequence
- ural 1306. Sequence Median
- ural 1306. Sequence Median
- Ural 1306. Sequence Median
- URAL 1306. Sequence Median
- Ural 1306. Sequence Median
- Ural 1306 Sequence Median
- ural Brackets Sequence (dp)
- ural 1306 Sequence Median
- Ural 1081. Binary Lexicographic Sequence
- ural 1247. Check a Sequence
- ural 1081 Binary Lexicographic Sequence
- ural 1081. Binary Lexicographic Sequence
- URAL 1306-Sequence Median(堆)
- URAL 1247 Check a Sequence
- Ural 1081 Binary Lexicographic Sequence
- android 开启闪光灯
- 我还没有弄明白的问题---20140723
- 深入理解Lua的全局变量_G以及源码实现
- kmp 的next 数组求法
- 整数动态
- Sequence - URAL 1528 水题
- 手机电话号码正则
- 判断一个请求是否是ajax
- poj 1469 COURSES(二分匹配模板)
- 自己动手编译、运行Java程序
- [LeetCode]Two Sum
- Java版CKFinder无法显示缩略图问题
- 的方式将第一任客单价的境地
- 开心一刻