POJ 3146 Interesting Yang Hui Triangle
来源:互联网 发布:淘宝双十一抢货攻略 编辑:程序博客网 时间:2024/05/19 12:28
Description
Harry is a Junior middle student. He is very interested in the story told by his mathematics teacher about the Yang Hui triangle in the class yesterday. After class he wrote the following numbers to show the triangle our ancestor studied.
He found many interesting things in the above triangle. It is symmetrical, and the first and the last numbers on each line is 1; there are exactly i numbers on the line i.
Then Harry studied the elements on every line deeply. Of course, his study is comprehensive.
Now he wanted to count the number of elements which are the multiple of 3 on each line. He found that the numbers of elements which are the multiple of 3 on line 2, 3, 4, 5, 6, 7, … are 0, 0, 2, 1, 0, 4, … So the numbers of elements which are not divided by 3 are 2, 3, 2, 4, 6, 3, …, respectively. But he also found that it was not an easy job to do so with the number of lines increasing. Furthermore, he is not satisfied with the research on the numbers divided only by 3. So he asked you, an erudite expert, to offer him help. Your kind help would be highly appreciated by him.
Since the result may be very large and rather difficult to compute, you only need to tell Harry the last four digits of the result.
Input
There are multiple test cases in the input file. Each test case contains two numbers P and N, (P < 1000, N ≤ 109), where P is a prime number and N is a positive decimal integer.
P = 0, N = 0 indicates the end of input file and should not be processed by your program.
Output
For each test case, output the last four digits of the number of elements on the N + 1 line on Yang Hui Triangle which can not be divided by P in the format as indicated in the sample output.
Sample Input
3 43 480 0
Sample Output
Case 1: 0004Case 2: 0012
#include<iostream>#include<stdlib.h>#include<cstdio>#include<algorithm>#include<cstring>#include<queue>#include<vector>#include<math.h>#include<time.h>using namespace std;int main(){ int p,n; int coun=0; while(scanf("%d%d",&p,&n)!=EOF) { if(p==0&&n==0) break; int ans=1; while(n) { ans=ans*(n%p+1); n=n/p; if(ans>=10000) ans%=10000; } printf("Case %d: %04d\n",++coun,ans); } return 0;}
- POJ 3146 Interesting Yang Hui Triangle
- POJ 3146 Interesting Yang Hui Triangle 笔记
- poj 3146 Interesting Yang Hui Triangle (Lucas定理)
- poj 3146/hdu 3304/uva 1384 Interesting Yang Hui Triangle Lucas定理
- poj 3146 Interesting Yang Hui Triangle(lucas定理的应用)
- LA3700 Interesting Yang Hui Triangle(Lucas定理)
- HDU3304 POJ3146 Interesting Yang Hui Triangle Lucas定理
- POJ 3146 & HDU 3304 Interesting Yang Yui Triangle(杨辉三角)
- hdu 3304 Interesting Yang Yui Triangle
- HDU 3304 Interesting Yang Yui Triangle lucas定理
- hui
- hdu3306Interesting Yang Yui Triangle+LUCAS定理
- yang
- Yang
- POJ 1269 Interesting Lines
- interesting
- interesting
- Interesting!
- 人事管理系统实现(三)
- ReactNative 安卓打包发布
- [WPF疑难]避免窗口最大化时遮盖任务栏
- 优惠码:牛客网-直通BAT面试算法精品课
- ZABBIX 微信报警 插件(python无图)
- POJ 3146 Interesting Yang Hui Triangle
- 智利外贸:Redcompra支付
- CI Weekly #13 | 用更 Geek 的方式配置你的 CI 工作流
- kurento-hello-world V6.0源码分析
- 网站屏蔽360或者google chrome浏览器
- canvas-图像布局填充
- final 关键字
- SQL Server 批量删除重复记录(批量、快速、安全)
- IO流_异常、File总结