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 摘要:最早接触马尔可夫模型的定义源于吴军先生<数学之美>一书,起初觉得深奥难懂且无什么用场.直到学习自然语言处 ...
随机推荐
- Fiddler模拟POST请求
在进行接口测试时,会模拟post请求,发送不同的请求参数,返回不同的结果,今天我们就来分享一下,怎么用Fiddler工具模拟post请求: 打开Fiddler工具,在右侧点击“composer”的选项 ...
- 关于img
为img添加属性max-width min-height之类的属性可以对图片溢出部分实行自动裁剪功能 非常方便!!!!!!!!!(仅适用于那些原始图片大于max-width,max-height的图片 ...
- Ukulele 常用和弦
- ios调试小结
Xcode底部的小黑盒是我们调试时的好朋友,它可以输出日志信息.错误信息以及其他有用的东西来帮你跟踪错误,除了可以看到日志直接输出的信息外,我们编程过程中也可以在某些断点停留,来检查app的多个方面. ...
- 830. Positions of Large Groups@python
In a string S of lowercase letters, these letters form consecutive groups of the same character. For ...
- GIMP语言设置
初学GIMP,需要设置语言:点击 编辑 - 首选项 其他的配置如: 配置快捷键 自己熟悉吧!
- heartbeat安装配置
一.环境 node01 192.168.127.101 心跳:192.168.42.101 node02 192.168.127.102 心跳:192.168.42.102 虚拟ip:192.168. ...
- laravel模型关联与列表展示
上面这个是一个模型关联的图,其实我们很容易去理解 比如说,一对一,也就是说一个用户对应的是一个手机号. 一对多,比如说一篇文章可以有多条评论 一对多反向:如一篇文章可以有多条评论,但对应每条评论也只针 ...
- 【css】清楚浏览器端缓存
/css/common.css?version=1.0.7 在css链接后面加个参数版本号控制,刷新浏览器缓存
- iOS设置UINavigationBar 的样式
为了方便演示,我用storyBoard建立了一个基本的导航栏 并在代码中获得了NavgationBar UINavigationBar *bar = self.navigationController ...