题意:给你n个东西,叫你把n分成任意段,这样的分法有几种(例如3:1 1 1,1 2,2 1,3 ;所以3共有4种),n最多有1e5位,答案取模p = 1e9+7

思路:就是往n个东西中间插任意个板子,所以最多能插n - 1个,所以答案为2^(n - 1) % p。但是n最大有1e5位数,所以要用小费马定理化简。

小费马定理:假如p是质数,且gcd(a,p)=1,那么a (p-1)≡1(mod p)

所以我们只要把n - 1分解为n - 1 = k(p - 1) + m,而2^ k(p - 1) % p ≡1,所以2^(n - 1) % p = 2^m % p,化简完成。

所以我们把n - 1对p-1取模,用了大数取模

代码:

#include<queue>
#include<cstring>
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<vector>
#include<cstdio>
#include<iostream>
#include<algorithm>
typedef long long ll;
const int maxn = 1e5 + ;
const int seed = ;
const ll MOD = 1e9 + ;
const ll MOD1 = 1e9 + ;
const int INF = 0x3f3f3f3f;
using namespace std;
char num[maxn];
/*ll getmod(){
ll ans = num[0] - '0';
int len = strlen(num);
for(int i = 1; i < len; i++)
ans = (ans * 10 + num[i] - '0') % MOD1;
return ans - 1;
}*/
ll getmod(){
ll ans = num[] - '';
int len = strlen(num);
for(int i = ; i < len - ; i++)
ans = (ans * + num[i] - '') % MOD1;
if(len > ) ans = ans * + num[len - ] - '';
return (ans - ) % MOD1;
}
ll pmul(ll a, ll b){
ll ans = ;
while(b){
if(b & ) ans = (ans * a) % MOD;
a = a * a % MOD;
b >>= ;
}
return ans;
}
int main(){
int T;
ll n, p;
scanf("%d", &T);
while(T--){
scanf("%s", num);
p = getmod();
printf("%lld\n", pmul(, p));
}
return ;
}

ACM-ICPC 2018 焦作赛区网络预赛G Give Candies(隔板定理 + 小费马定理 + 大数取模,组合数求和)题解的更多相关文章

  1. 【费马小定理+快速幂取模】ACM-ICPC 2018 焦作赛区网络预赛 G. Give Candies

    G. Give Candies There are N children in kindergarten. Miss Li bought them N candies. To make the pro ...

  2. ACM-ICPC 2018 焦作赛区网络预赛 G. Give Candies (打表找规律+快速幂)

    题目链接:https://nanti.jisuanke.com/t/31716 题目大意:有n个孩子和n个糖果,现在让n个孩子排成一列,一个一个发糖果,每个孩子随机挑选x个糖果给他,x>=1,直 ...

  3. ACM-ICPC 2018 焦作赛区网络预赛 G Give Candies(高精度求余)

    https://nanti.jisuanke.com/t/31716 题意 n颗糖果n个人,按顺序给每个人任意数目(至少一个)糖果,问分配方案有多少. 分析 插板法或者暴力打表后发现答案就为2^(n- ...

  4. ACM-ICPC 2018 焦作赛区网络预赛 G Give Candies

    There are NNN children in kindergarten. Miss Li bought them NNN candies. To make the process more in ...

  5. ACM-ICPC 2018 焦作赛区网络预赛- G:Give Candies(费马小定理,快速幂)

    There are N children in kindergarten. Miss Li bought them NNN candies. To make the process more inte ...

  6. ACM-ICPC 2018 焦作赛区网络预赛 G题 Give Candies

    There are NN children in kindergarten. Miss Li bought them NN candies. To make the process more inte ...

  7. ACM-ICPC 2018 焦作赛区网络预赛

    这场打得还是比较爽的,但是队友差一点就再过一题,还是难受啊. 每天都有新的难过 A. Magic Mirror Jessie has a magic mirror. Every morning she ...

  8. ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心)

    ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in t ...

  9. ACM-ICPC 2018 焦作赛区网络预赛- L:Poor God Water(BM模板/矩阵快速幂)

    God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...

随机推荐

  1. 优云软件应邀出席 ITSS 数据中心运营管理工作组 2017 年春季研讨会

    2017 年 4 月 15 日,中国电子工业标准化技术协会信息技术服务分会(以下称 ITSS 分会)数据中心运营管理工作组(以下简称 DCMG)在江苏省启东市召开春季研讨会. DCMG 工作组组长肖建 ...

  2. 【python-opencv】15-图像阈值

    [微语]立志要如山,行道要如水.不如山,不能坚定,不如水,不能曲达 import cv2 as cv import numpy as np from matplotlib import pyplot ...

  3. java动态加载

    先贴个笔记,后续用得着再深究. package test; import java.io.File; import java.io.IOException; import java.lang.refl ...

  4. MYSQL中的BlackHole引擎

    MYSQL中的BlackHole引擎 http://blog.csdn.net/ylspirit/article/details/7234021 http://blog.chinaunix.net/u ...

  5. Celery框架简单实例

    Python 中可以使用Celery框架 Celery框架是提供异步任务处理的框架,有两种用法,一种:应用程式发布任务消息,后台Worker监听执行,好处在于不影响应用程序继续执行.第二种,设置定时执 ...

  6. js-jquery-Validate校验【一】

    一.导入 js 库 <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/lib/jquery.j ...

  7. golang语言中的context详解,Go Concurrency Patterns: Context

    https://blog.golang.org/context Introduction In Go servers, each incoming request is handled in its ...

  8. (转)ElasticSearch Java Api-检索索引库

    上篇博客记录了如何用java调用api把数据写入索引,这次记录下如何搜索. 一.准备数据 String data1 = JsonUtil.model2Json(new Blog(1, "gi ...

  9. 主成分分析(PCA)算法,K-L变换 角度

    主成分分析(PCA)是多元统计分析中用来分析数据的一种方法,它是用一种较少数 量的特征对样本进行描述以达到降低特征空间维数的方法,它的本质实际上是K-L变换.PCA方法最著名的应用应该是在人脸识别中特 ...

  10. DirectShow SDK下载

    http://blog.csdn.net/zx3517288/article/details/50547243 Q : GRMSDK_EN_DVD.iso 5 67.3MBGRMSDKIAI_EN_D ...