URAL 1528 Sequence
来源:互联网 发布:esxi 6.0 网络配置 编辑:程序博客网 时间:2024/06/08 12:02
SequenceCrawling in process...Crawling failedTime Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
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 + 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 findf(n) mod p.
Input
The input consists of several cases. Each case contains two numbers on a single line. These numbers aren (1 ≤ n ≤ 10000) and p (2 ≤ p ≤ 2·109). The input is terminated by the case withn = 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
题意:如题。
思路:哇。一开始看错题啦。不难发现f(n)的通项啦。
AC代码:
#include <cstdio>#include <iostream>#include <algorithm>#include <cmath>#include <cstring>#include <stdlib.h>using namespace std;int main(){ int n,p; while(~scanf("%d%d",&n,&p)){ if(n==0&&p==0) break; long long ans=1; for(int i=2;i<=n;i++){ ans*=i%p; ans%=p; } printf("%d\n",ans%p); } 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
- 优先队列2
- 微信公众平台 自定义菜单类库
- 配置NFS
- Spring声明式事务管理详解
- 浏览器正确显示csv文件
- URAL 1528 Sequence
- Hadoop配置项整理(hdfs-site.xml)
- Java NIO ServerSocketChannel
- IT忍者神龟之修改IE地址栏Tomcat 小猫咪图标
- STL源码阅读-iterator
- ROS发展之路 -版本回顾篇
- Hibernate操作数据库的3个准备和七个步骤,以及在SSH框架中Hibernate的配置。
- Mybatis和Ibatis的区别
- 从汇编的角度看栈