$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. IOS Array 排序方法

    NSArray *sortedArray = [array sortedArrayUsingComparator: ^(id obj1, id obj2) { if ([obj1 integerVal ...

  2. js 下载文件/导出

    const url = '/sasd/fsd/xxxx/exportMailData2Excel'this.downloadFile(url, 'blob', this.isSearch) // 调用 ...

  3. OpenRead方法打开文件并读取

    实现效果: 知识运用: File类的OpenRead方法 //实现打开现有文件以进行读取 public static FileStream OpenRead(string path) FileStre ...

  4. Bootstrap历练实例:分页状态

    分页的状态 下面的实例演示了上表中所讨论的 class .disabled..active 的用法: <!DOCTYPE html><html><head>< ...

  5. Php教程

    第一部:PHP基础部分(131集,发布完毕) 讲html与PHPt基础,PHP环境搭建,与留言本编写. 下载地址:① HTML视频[2014新版] http://pan.baidu.com/s/1ve ...

  6. ios 团购信息客户端demo(一)

    团购信息客户端,主要整合了ASIHTTPREQUEST,KISSXML,AQGridView,MBProgressHUD这几个主要流行的IOS开发库,我们先来看一下效果图 首先我们新建一个IOS工程, ...

  7. touch-action css属性 滚动和缩放手势

    CSS 属性 touch-action 用于指定某个给定的区域是否允许用户操作,以及如何响应用户操作(比如浏览器自带的划动,缩放等) 默认情况下,平移(滚动) 和 缩放手势由浏览器专门处理.该属性用于 ...

  8. 【OS_Linux】yum命令安装软件

    1.YUM的简介 Yum(全称为 Yellow dog Updater, Modified)是一个rpm包管理器.它能够从指定的服务器上自动下载RPM包并安装,可以自动处理包之间的依赖性关系,并且一次 ...

  9. 初识Pyhon之准备环境

    安装成功python的运行环境之后,你可能要迫不及待大展身手了 如果你有一定的语言基础,那么基础这一块儿就可以简单的看看就可以了,但是你是一个编程语言的初学者.不着急,慢慢往下看 打开pycharm创 ...

  10. 二、Pandas库与数据处理

    # Author:Zhang Yuan import pandas as pd import numpy as np #Pandas提供了两大数据结构:一维结构的Series类型.二维结构的DataF ...