方程的解_NOI导刊2010提高(01) 组合数
题目描述
佳佳碰到了一个难题,请你来帮忙解决。
对于不定方程a1+a2+…+ak-1+ak=g(x),其中k≥2且k∈N,x是正整数,g(x)=x^x mod 1000(即x^x除以1000的余数),x,k是给定的数。我们要求的是这个不定方程的正整数解组数。
举例来说,当k=3,x=2时,分别为(a1,a2,a3)=(2,1,1)'(1,2,1),(1,1,2)。
输入输出格式
输入格式:
输入文件equation.in有且只有一行,为用空格隔开的两个正整数,依次为k,x。
输出格式:
输出文件equation.out有且只有一行,为方程的正整数解组数。
输入输出样例
说明
对于40%的数据,ans≤10^16;对于100%的数据,k≤100,x≤2^31-1,k≤g(x)。
_NOI导刊2010提高(01)
隔板法:
C(x-1,k-1) ;
然后高精度就行了;
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 900005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-3
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ const int W = 10000000;
int x, k;
struct bigint {
int a[25], len;
bigint() {
ms(a); len = 0;
}
bigint operator +(const bigint &rhs)const {
bigint c; int x = 0;
c.len = max(len, rhs.len);
for (int i = 1; i <= c.len; i++) {
c.a[i] = a[i] + rhs.a[i] + x;
x = c.a[i] / W; c.a[i] %= W;
}
for (; x; x /= W)c.a[++c.len] = x % W;
return c;
}
void print() {
cout << a[len];
for (int i = len - 1; i >= 1; i--) {
for (int j = 10; a[i] * j < W; j *= 10)
putchar(48);
cout << a[i];
}
}
}c[1003][1003];
int qpow(int x, int y) {
int res = 1;
while (y) {
if (y % 2)res = 1ll * res*x % 1000;
x = x * x % 1000; y >>= 1;
}
return res;
} int main() {
//ios::sync_with_stdio(0);
rdint(k); rdint(x); x %= 1000; x = qpow(x, x);
for (int i = 0; i < x; i++) {
for (int j = 0; j <= i; j++) {
if (!j || j == i)c[i][j].a[c[i][j].len = 1] = 1;
else c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
}
}
c[x - 1][k - 1].print();
return 0;
}
方程的解_NOI导刊2010提高(01) 组合数的更多相关文章
- P1771 方程的解_NOI导刊2010提高(01)
P1771 方程的解_NOI导刊2010提高(01) 按题意用快速幂把$g(x)$求出来 发现这不就是个组合数入门题吗! $k$个人分$g(x)$个苹果,每人最少分$1$个,有几种方法? 根据插板法, ...
- 洛谷P1771 方程的解_NOI导刊2010提高(01)
题目描述 佳佳碰到了一个难题,请你来帮忙解决. 对于不定方程a1+a2+…+ak-1+ak=g(x),其中k≥2且k∈N,x是正整数,g(x)=x^x mod 1000(即x^x除以1000的余数), ...
- 方程的解_NOI导刊2010提高
方程的解 给定x,求\(a_1+a_2+...+a_k=x^x\ mod\ 1000\)的正整数解解的组数,对于100%的数据,k≤100,x≤2^31-1. 解 显然x是可以快速幂得到答案的,而该问 ...
- 洛谷 P1777 帮助_NOI导刊2010提高(03) 解题报告
P1777 帮助_NOI导刊2010提高(03) 题目描述 Bubu的书架乱成一团了!帮他一下吧! 他的书架上一共有n本书.我们定义混乱值是连续相同高度书本的段数.例如,如果书的高度是30,30,31 ...
- 洛谷—— P1775 古代人的难题_NOI导刊2010提高(02)
P1775 古代人的难题_NOI导刊2010提高(02) 题目描述 门打开了,里面果然是个很大的厅堂.但可惜厅堂内除了中央的一张羊皮纸和一支精致的石笔,周围几具骷髅外什么也没有.难道这就是王室的遗产? ...
- P1799 数列_NOI导刊2010提高(06)
P1799 数列_NOI导刊2010提高(06)f[i][j]表示前i个数删去j个数得到的最大价值.if(i-j==x) f[i][j]=max(f[i][j],f[i-1][j]+1); else ...
- 【洛谷】【堆】P1801 黑匣子_NOI导刊2010提高(06)
[题目描述:] Black Box是一种原始的数据库.它可以储存一个整数数组,还有一个特别的变量i.最开始的时候Black Box是空的.而i等于0.这个Black Box要处理一串命令. 命令只有两 ...
- P1776 宝物筛选_NOI导刊2010提高(02)&& 多重背包二进制优化
多重背包, 要求 \(N\log N\) 复杂度 Solution 众所周和, \(1-N\) 之内的任何数可以由 \(2^{0}, 2^{1}, 2^{2} ... 2^{\log N}, N - ...
- P1801 黑匣子_NOI导刊2010提高(06)
P1801 黑匣子_NOI导刊2010提高(06) 题目描述 Black Box是一种原始的数据库.它可以储存一个整数数组,还有一个特别的变量i.最开始的时候Black Box是空的.而i等于0.这个 ...
随机推荐
- codeforces 631C C. Report
C. Report time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- swiper轮播 swiper整屏轮播
近期坐了几个移动端 整屏轮播的 效果 之前都是自己一个个写,之前听说过swiper插件,没有使用过,今天一尝试,果然,爽 使用方法示例 <div class="swiper-cont ...
- BZOJ4317: Atm的树+2051+2117
BZOJ4317: Atm的树+2051+2117 https://lydsy.com/JudgeOnline/problem.php?id=4317 分析: 二分答案之后就变成震波那道题了. 冷静一 ...
- tarjan求割点
首先给大家一个网址讲的比较细:http://www.cnblogs.com/en-heng/p/4002658.html 如果还有不懂的话,可以回来再看看我的文章; 概念明确: 树边:(在[2]中称为 ...
- P1030 求先序排列
题目描述 给出一棵二叉树的中序与后序排列.求出它的先序排列.(约定树结点用不同的大写字母表示,长度<=8). 输入输出格式 输入格式: 2行,均为大写字母组成的字符串,表示一棵二叉树的中序与后序 ...
- jQuery DataTables 使用手册(精简版)
转载请注明出处:http://www.cnblogs.com/shamoyuu/p/5182940.html 前排提醒,这个插件能不用就不用,那么多好的插件等着你,为什么要用它呢?就算用easyui的 ...
- scrollHeight
scrollHeight=显示内容高度+隐藏内容高度 参考: https://developer.mozilla.org/en-US/docs/Web/API/Element.scrollHeight ...
- 洛谷 2312 / bzoj 3751 解方程——取模
题目:https://www.luogu.org/problemnew/show/P2312 https://www.lydsy.com/JudgeOnline/problem.php?id=3751 ...
- 外置式与增量式PID模板程序(51单片机c语言)
外置式PID模板 #define MuBiaoCS 0 //目标常数 #define CHang_aCS 0 //比例常数 #define CHang_bCS 0 //积分常数 #define CHa ...
- content-disposition attachment filename 在Firefox和IE中得到不同的结果
在Firefox中需要把filename 用双引号包起来,才能得到想要的名字,不然如果含有空格,会丢掉空格后面的部分.而IE会把空格转为_,因此也需要HttpUtility.UrlPathEncode ...