URAL 1528Sequence
来源:互联网 发布:金融富豪 知乎 编辑:程序博客网 时间:2024/06/08 09:50
Description
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 + 2 g(1) + 2 g(2) + 2 g(3) + … + 2 g( 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·10 9). 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
1 22 110 0
12
题目在吓唬人啊,仔细算一算这个就是阶乘啊。
#include<cstdio>#include<cstring>#include<iostream>#include<string>#include<algorithm>using namespace std;int main(){int n, p;while (cin >> n >> p, n, p){long long tot = 1;for (int i = 1; i <= n; i++) tot = tot*i%p;cout << tot << endl;}return 0;}
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
- Hibernate中get和load方法的区别 参考网址:http://love-love-l.blog.163.com/blog/static/210783042009618919985/
- 1097 A hard puzzle
- 自律乃是人生的首要原则——《少有人走的路》
- RelativeLayout中layout_CenterInParent="true"失效的原因
- POJ 1742 Coins
- URAL 1528Sequence
- POJ 2155 Matrix
- 首次开通博客
- Codeforces Round #292 (Div. 2)。
- 1098 数学题
- UVALive 6092 Catching Shade in Flatland
- UVa #12186 Another Crisis (例题9-12)
- Circum Triangle - UVa 11186 三角形面积
- 看过贺岁片,你知道贺岁课程吗?