$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的更多相关文章

  1. bzoj 1902: Zju2116 Christopher lucas定理 && 数位DP

    1902: Zju2116 Christopher Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 172  Solved: 67[Submit][Stat ...

  2. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  3. bzoj1902【Zju2116】 Christopher

    题意:http://www.lydsy.com/JudgeOnline/problem.php?id=1902 sol  :一眼可以看出此题应用了lucas定理(逃~ 将n,m都化为p进制,记为a[] ...

  4. Christopher G. Atkeson 简介

    有一个事实:双足机器人的稳定性问题单靠算法是搞不定的!!! 在2015 DARPA 机器人挑战赛中,许多参赛团队的机器人使用了Atlas,他们通过安装他们自己的软件并修改来让机器人保持平衡.来自WPI ...

  5. Day3----《Pattern Recognition and Machine Learning》Christopher M. Bishop

    其实今天只花了一点点时间来学习这本书, 如果模型的参数过多,而训练数据又不足够多的话,就会出现overfitting. overfitting可以通过regularization来解决,贝叶斯方法也可 ...

  6. Day2----《Pattern Recognition and Machine Learning》Christopher M. Bishop

    用一个例子来讲述regression. 采用sin(2*pi*x)加入微弱的正态分布噪声的方式来获得一些数据,然后用多项式模型来进行拟合. 在评价模型的准确性时,采用了误差函数的方式,用根均方误差的方 ...

  7. 学习笔记-----《Pattern Recognition and Machine Learning》Christopher M. Bishop

    Preface 模式识别这个词,以前一直不懂是什么意思,直到今年初,才开始打算读这本广为推荐的书,初步了解到,它的大致意思是从数据中发现特征,规律,属于机器学习的一个分支. 在前言中,阐述了什么是模式 ...

  8. [BZOJ1902]:[NOIP2004]虫食算(搜索)

    题目传送门 题目描述 所谓虫食算,就是原先的算式中有一部分被虫子啃掉了,需要我们根据剩下的数字来判定被啃掉的字母. 来看一个简单的例子: 43#98650#45+8468#6633=444455069 ...

  9. 【NLP】揭秘马尔可夫模型神秘面纱系列文章(一)

    初识马尔可夫和马尔可夫链 作者:白宁超 2016年7月10日20:34:20 摘要:最早接触马尔可夫模型的定义源于吴军先生<数学之美>一书,起初觉得深奥难懂且无什么用场.直到学习自然语言处 ...

随机推荐

  1. python基础一 day14 生成器函数进阶

    def generator(): print(123) content = yield 1 print('=======',content) print(456) arg = yield 2 '''' ...

  2. 标注偏置问题(Label Bias Problem)和HMM、MEMM、CRF模型比较<转>

    转自http://blog.csdn.net/lskyne/article/details/8669301 路径1-1-1-1的概率:0.4*0.45*0.5=0.09 路径2-2-2-2的概率:0. ...

  3. xheditor的实例程序—类似word的编辑器

    编辑器工具栏:类似word的编辑器 1.1.下载,兼容性 xhEditor官方网站地址为:http://xheditor.com/,打开右上角的免费下载 | 参数向导链接,即可找到最新版本的下载地址. ...

  4. ios之alloc和init

      复制代码 SomeObject *obj = [[SomeObject alloc] initWithCenter:centerPoint radius:radius]; 和   复制代码 Som ...

  5. nginx在windows上面的启动bat文件

    因为windows上面zip安装nginx后启动比较麻烦,然后找了一下关于批处理文件的资料,写了一个nginx启动和关闭的脚本. 这个脚本正常情况下是可以使用的.因为脚本中并没有对nginx程序是否在 ...

  6. [LUOGU] 1364 医院设置

    设有一棵二叉树,如图: [我是图] 其中,圈中的数字表示结点中居民的人口.圈边上数字表示结点编号,现在要求在某个结点上建立一个医院,使所有居民所走的路程之和为最小,同时约定,相邻接点之间的距离为1.如 ...

  7. python3.x 多路IO复用补充asyncio

    asyncio模块是python之父写的模块,按说应该是靠谱的,python3.6版本定义为稳定版本. 说明书:https://docs.python.org/3/library/asyncio.ht ...

  8. python爬虫(爬取视频)

    爬虫爬视频 爬取步骤 第一步:获取视频所在的网页 第二步:F12中找到视频真正所在的链接 第三步:获取链接并转换成机械语言 第四部:保存 保存步骤代码 import re import request ...

  9. DRF框架中的演变View

    import json from django.db import DatabaseError from django.http import HttpResponse from django.htt ...

  10. Bin Paking Problem:简单的构造性算法

    *本文主要记录和分享学习到的知识,算不上原创 *参考文献见链接 目录 BL和BLF算法 BF算法 HR算法 PH算法