方程的解_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.这个 ...
随机推荐
- FileInputStream 原理总结 把文件作为字节流进行读操作
package io; import java.io.FileInputStream; import java.io.IOException; public class IOUtil { /** * ...
- MarkDown不支持图片放缩。。

Elina is reading a book written by Rujia Liu, which introduces a strange way to express non-negative ...
- ACM学习历程—51NOD1028 大数乘法V2(FFT)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1028 题目大意就是求两个大数的乘法. 但是用普通的大数乘法,这 ...
- 一个内存增长问题的分析和处理(二)——valgrind工具的用法
valgrind是linux下对C++和C程序进行内存泄露检测的工具,除了内存检测,valgrind还提供了很多其他的功能,这里主要介绍下valgrind的内存检测的功能. 首先是文件的下载,valg ...
- Javascript:必须知道的Javascript知识点之“单线程事件驱动”
heiboard: Javascript:必须知道的Javascript知识点之“单线程事件驱动”
- Poj_1008--Maya Calendar
一.Description 上周末,M.A. Ya教授对古老的玛雅有了一个重大发现.从一个古老的节绳(玛雅人用于记事的工具)中,教授发现玛雅人使用了一个一年有365天的叫做Haab的历法.这个Haab ...
- Python图片识别——人工智能篇
一.安装pytesseract和PIL PIL全称:Python Imaging Library,python图像处理库,这个库支持多种文件格式,并提供了强大的图像处理和图形处理能力. 由于PIL仅 ...