Interesting Yang Yui Triangle(hdu3304)
Interesting Yang Yui Triangle
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 332 Accepted Submission(s): 199
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.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
......
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.
are multiple test cases in the input file. Each test case contains two
numbers P and N , (P < 1000, N<=10^9) , 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.
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.
1 #include <cstdio>
2 #include <cstdlib>
3 #include <cstring>
4 #include <cmath>
5 #include <iostream>
6 #include <algorithm>
7 #include <map>
8 #include <queue>
9 #include <vector>
10 #include<set>
11 using namespace std;
12 typedef long long LL;
13 int main(void)
14 {
15 LL p,N;
16 int __ca=0;
17 while(scanf("%lld %lld",&p,&N),p!=0||N!=0)
18 {
19 LL sum=1;
20 while(N)
21 {
22 int mod=N%p;
23 sum*=mod+1;
24 sum%=10000;
25 N/=p;
26 }printf("Case %d: ",++__ca);
27 printf("%04d\n",sum);
28 }
29 return 0;
30 }
Interesting Yang Yui Triangle(hdu3304)的更多相关文章
- hdu 3304 Interesting Yang Yui Triangle
hdu 3304 Interesting Yang Yui Triangle 题意: 给出P,N,问第N行的斐波那契数模P不等于0的有多少个? 限制: P < 1000,N <= 10^9 ...
- HDU 3304 Interesting Yang Yui Triangle lucas定理
输入p n 求杨辉三角的第n+1行不能被p整除的数有多少个 Lucas定理: A.B是非负整数,p是质数.AB写成p进制:A=a[n]a[n-1]...a[0],B=b[n]b[n-1]...b[0] ...
- UVALive - 3700 Interesting Yang Hui Triangle
题目大意就是求一下 杨辉三角的第N行中不能被P整除的有多少个. 直接卢卡斯定理一下就行啦. #include<bits/stdc++.h> #define ll long long usi ...
- UVAL3700
Interesting Yang Hui Triangle 题目大意:杨辉三角第n + 1行不能整除p(p是质数)的数的个数 题解: lucas定理C(n,m) = πC(ni,mi) (mod p) ...
- 武大OJ 613. Count in Sama’s triangle
Description Today, the math teacher taught Alice Hui Yang’s triangle. However, the teacher came up w ...
- [SinGuLaRiTy] 组合数学题目复习
[SinGuLaRiTy] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. [CQBZOJ 2011] 计算系数 题目描述 给定一个多项式( ...
- hdu 3944 dp?
DP? Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 128000/128000 K (Java/Others)Total Subm ...
- hdu 3944 DP? 组合数取模(Lucas定理+预处理+帕斯卡公式优化)
DP? Problem Description Figure 1 shows the Yang Hui Triangle. We number the row from top to bottom 0 ...
- 编程输出杨辉三角的前10行---多维数组的应用---java实现
import java.util.Scanner;public class yanghui{ public static void main(String[] args){ Scanner sc=n ...
随机推荐
- TCP的慢启动、拥塞避免、重传、快恢复乱七八糟总是记不清?11个连环问让你一次性打通任督二脉
摘要:如果你的开发过程涉及数据传输,一直在重传.超时之类的方案里有困惑的话,不妨重新学一学可靠性最精致的TCP协议. 本文分享自华为云社区<TCP的慢启动.拥塞避免.重传.快恢复乱七八糟总是记不 ...
- acquire, acre, across
acquire An acquired taste is an appreciation [鉴赏] for something unlikely to be enjoyed by a person w ...
- day04 查找关键字
day04 查找关键字 昨日内容回顾 基本数据类型之日期相关类型 date :年月日 time :时分秒 datetime:年月日时分秒 year :年 基本数据类型之枚举与集合类型 # 枚举 多选一 ...
- 【leetcode】952. Largest Component Size by Common Factor(Union find)
You are given an integer array of unique positive integers nums. Consider the following graph: There ...
- Linux基础命令---ntpdate网络时间服务器
ntpdate ntpdate指令通过轮询指定为服务器参数的网络时间协议(NTP)服务器来设置本地日期和时间,从而确定正确的时间. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS ...
- React 传值 组件传值 之间的关系
react 组件相互之间的传值: 传值分父级组件传值给子组件 子组件传值给父组件 平级组件.没有嵌套的组件相互传值 1.父组件向子组件传值 父组件通过属性的形式来向子组件传值,子组件通过pr ...
- 使用jstl和el表达式来展示request域中存放的user对象的信息
<%@ page import="java.util.ArrayList" %><%@ page import="java.util.List" ...
- Python 如何管理类的创建行为
问题 如果我们要给类加上一个属性,只需在定义的时候加上属性就可以了: class Animal: can_fly = True 如果这样的类有很多,我们可以定义一个父类,让其它类继承他就可以了: cl ...
- Linux驱动实践:一起来梳理中断的前世今生(附代码)
作 者:道哥,10+年嵌入式开发老兵,专注于:C/C++.嵌入式.Linux. 关注下方公众号,回复[书籍],获取 Linux.嵌入式领域经典书籍:回复[PDF],获取所有原创文章( PDF 格式). ...
- Windows10下mysql 8.0.19 安装配置方法图文教程
第一步 下载安装包: 官网 毕竟是甲骨文公司的产品,去官网下真的慢! 这里有两个供选择的,我建议选第一个(因为我先下了第二个,结果失败了,不知道为什么总是出错.) 下载完自行选择路径解压就可以了. 第 ...