BZOJ1902: Zju2116 Christopher
$n \leq 10^{100}$,问$C_n^m,0<=m<=n$有多少是质数$p \leq 1e7$的倍数。
一样,套高精度的题,只有战胜他才能鄙视他。
但是我TM被他鄙视了一上午!!!
好先冷静分析。用Lucas的观点看组合数,这里就是个明显的数位DP了,统计每一位时大于当前数、小于等于当前数的合法和不合法方案数,很简单的转移,详见代码。
被鄙视*1:方程抄错了。。
被鄙视*2:高精度乘单精度乘法写错了。。
当然这也不能怪我鬼知道他有乘零!
好吧怪我
//#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
//#include<vector>
//#include<queue>
//#include<time.h>
//#include<complex>
#include<algorithm>
#include<stdlib.h>
using namespace std; int n;
#define maxn 1011
int a[maxn],mod,b[maxn],lb; char s[maxn]; int len; #define LL long long
struct LLL
{
int a[],len;
LLL() {memset(a,,sizeof(a)); len=;}
void operator = (int x)
{
len=;
while (x) a[++len]=x%,x/=;
}
void operator = (const LLL &b)
{
len=b.len;
for (int i=;i<=len;i++) a[i]=b.a[i];
}
LLL operator * (int x)
{
LLL ans;
for (int i=;i<=len;i++)
{
LL tmp=a[i]*1ll*x;
ans.a[i+]+=(ans.a[i]+tmp)/;
ans.a[i]=(ans.a[i]+tmp)%;
}
ans.len=len;
while (ans.a[ans.len+])
{
ans.len++;
if (ans.a[ans.len]>=) ans.a[ans.len+]+=ans.a[ans.len]/,ans.a[ans.len]%=;
}
while (ans.a[ans.len]== && ans.len>) ans.len--;
return ans;
}
LLL operator + (const LLL &b)
{
LLL ans;
for (int i=,to=max(len,b.len);i<=to;i++)
{
ans.a[i]+=a[i]+b.a[i];
if (ans.a[i]>=)
{
ans.a[i+]++;
ans.a[i]-=;
}
}
ans.len=max(len,b.len);
while (ans.a[ans.len+]) ans.len++;
return ans;
}
void out()
{
printf("%d",a[len]);
for (int i=len-;i>;i--)
{
for (int j=;j>;j/=) if (a[i]<j) putchar('');
printf("%d",a[i]);
}
}
}f[maxn][],g[maxn]; int main()
{
scanf("%s%d",s+,&mod); len=strlen(s+);
for (int i=;i<=len;i++) a[i]=s[len-i+]-'';
lb=; while (len)
{
int tmp=;
for (int i=len;i;i--) {int now=a[i]; a[i]=(tmp*+now)/mod; tmp=(tmp*+now)%mod;}
for (;len && a[len]==;len--);
b[++lb]=tmp;
}
f[][]=; f[][]=b[]+; g[]=mod--b[];
for (int i=;i<=lb;i++)
{
f[i][]=f[i-][]*(b[i]+)+g[i-]*b[i];
f[i][]=f[i-][]*(b[i]+);
g[i]=(f[i-][]+f[i-][])*(mod--b[i])+g[i-]*(mod-b[i]);
}
f[lb][].out();
return ;
}
BZOJ1902: Zju2116 Christopher的更多相关文章
- bzoj 1902: Zju2116 Christopher lucas定理 && 数位DP
1902: Zju2116 Christopher Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 172 Solved: 67[Submit][Stat ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- bzoj1902【Zju2116】 Christopher
题意:http://www.lydsy.com/JudgeOnline/problem.php?id=1902 sol :一眼可以看出此题应用了lucas定理(逃~ 将n,m都化为p进制,记为a[] ...
- Christopher G. Atkeson 简介
有一个事实:双足机器人的稳定性问题单靠算法是搞不定的!!! 在2015 DARPA 机器人挑战赛中,许多参赛团队的机器人使用了Atlas,他们通过安装他们自己的软件并修改来让机器人保持平衡.来自WPI ...
- Day3----《Pattern Recognition and Machine Learning》Christopher M. Bishop
其实今天只花了一点点时间来学习这本书, 如果模型的参数过多,而训练数据又不足够多的话,就会出现overfitting. overfitting可以通过regularization来解决,贝叶斯方法也可 ...
- Day2----《Pattern Recognition and Machine Learning》Christopher M. Bishop
用一个例子来讲述regression. 采用sin(2*pi*x)加入微弱的正态分布噪声的方式来获得一些数据,然后用多项式模型来进行拟合. 在评价模型的准确性时,采用了误差函数的方式,用根均方误差的方 ...
- 学习笔记-----《Pattern Recognition and Machine Learning》Christopher M. Bishop
Preface 模式识别这个词,以前一直不懂是什么意思,直到今年初,才开始打算读这本广为推荐的书,初步了解到,它的大致意思是从数据中发现特征,规律,属于机器学习的一个分支. 在前言中,阐述了什么是模式 ...
- [BZOJ1902]:[NOIP2004]虫食算(搜索)
题目传送门 题目描述 所谓虫食算,就是原先的算式中有一部分被虫子啃掉了,需要我们根据剩下的数字来判定被啃掉的字母. 来看一个简单的例子: 43#98650#45+8468#6633=444455069 ...
- 【NLP】揭秘马尔可夫模型神秘面纱系列文章(一)
初识马尔可夫和马尔可夫链 作者:白宁超 2016年7月10日20:34:20 摘要:最早接触马尔可夫模型的定义源于吴军先生<数学之美>一书,起初觉得深奥难懂且无什么用场.直到学习自然语言处 ...
随机推荐
- Linux OpenGL 实践篇-13-geometryshader
几何着色器 几何着色器是位于图元装配和片元着色器之前的一个着色器阶段,是一个可选阶段.它的输入是一个图元的完整的顶点信息,通常来自于顶点着色器,但如果细分计算着色器启用的话,那输入则是细分计算着色器的 ...
- Servlet The Filter
The Filter Filter不会产生Request或者是Response, 但是会在两者访问资源时, 对其作出改变.其可以作用于静态资源和动态资源. LifeCycle Filter会和Serv ...
- C#中当服务器返回的数据json中key的值为数字类型,解决方案
客户端向服务器发送请求后,服务器返回了一个json格式的字符串但是格式中key的值有些事数字{"1000":"55555"}; 类似这种格式的话就不能直接转化成 ...
- c++ 各种类型字符串转换
typedef std::string u8string; u8string To_UTF8(const std::u16string &s) { std::wstring_convert&l ...
- python--内置函数03
一 . 正则表达式 匹配字符串 元字符 . 除了换行 \w 数字, 字母, 下划线 \d 数字 \s 空白符 \n \t \b 单词的边界 \W 非xxx \D \S [ ] 字符组 or的关系 [^ ...
- python项目开发视频
精品Python项目开发学习视频 所属网站分类: 资源下载 > python视频教程 作者:乐天派 链接:http://www.pythonheidong.com/blog/article/44 ...
- LeetCode(91) Decode Ways
题目 A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A ...
- linux下C++的多线程编程
1. 引言 线程(thread)技术早在60年代就被提出,但真正应用多线程到操作系统中去,是在80年代中期,solaris是这方面的佼佼者.传统的Unix也支持线程的概念,但是在一个进程(proces ...
- Verilog学习笔记基本语法篇(二)·········运算符
Verilog HDL的语言的运算符的范围很广,按照其功能大概可以分为以下几类: (1)算术运算符 +,-,*,/,% 优先顺序 !~ * / % + - << > ...
- PAT Basic 1040
1040 有几个PAT 字符串APPAPT中包含了两个单词“PAT”,其中第一个PAT是第2位(P),第4位(A),第6位(T):第二个PAT是第3位(P),第4位(A),第6位(T). 现给定字符串 ...