方程的解_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.这个 ...
随机推荐
- linux命令学习笔记(57):ss命令
ss是Socket Statistics的缩写.顾名思义,ss命令可以用来获取socket统计信息,它可以显示和netstat 类似的内容.但ss的优势在于它能够显示更多更详细的有关TCP和连接状态的 ...
- C语言小程序(六)、数组操作
对数组进行操作,查找.插入.删除. #include <stdio.h> #include <stdlib.h> #include <time.h> int siz ...
- [原]NYOJ-数的位数-69
大学生程序代写 /* NYOJ69 阶乘数位长度 http://acm.nyist.net/JudgeOnline/problem.php?pid=69 数的长度 时间限制:3000 ms | ...
- CMake简易入门
使用CMake编译 CMake工具用于生成Makefile文件.用户通过编写CMakeLists.txt文件,描述构建过程(编译.连接.测试.打包),之后通过解析该文件,生成目标平台的Makefile ...
- 比线程更NB的存在
阅读目录 一 引子 二 协程介绍 三 Greenlet模块 四 Gevent模块 引子 之前我们学习了线程.进程的概念,了解了在操作系统中进程是资源分配的最小单位,线程是CPU调度的最小单位.按道理来 ...
- HDOJ1075字典翻译(map应用)
#include<iostream> #include<cstdio> #include<map> #include<string> #include& ...
- Foreman-porxy负载均衡搭建
本文接上篇puppet负载均衡的环境实验. Foreman-proxy可以采用四层或者七层负载,都可以实现,在foreman的web界面添加一个smart-proxy,后端多个真实foreman-pr ...
- Spring 学习十四 Spring security安全
Spring security: 我用过的安全机制: oauth2, filter, secured方法保护 9.2 保护web请求: 9.2.1 代理Servlet过滤器: Delegat ...
- 02_android下单元测试
Java的单元测试JUnit. Java程序入口是main方法.一般不在安卓程序入口 @Override protected void onCreate(Bundle savedInstanceSta ...
- cocos2dx v3.x lua绑定分析
打算新项目转到cocos2dx v3上了,下载代码浏览过后发现改动真是非常大,结构性调整很多. 比如tolua绑定这一块,就几乎全翻新了. 胶水代码的生成,改成了全自动式的,通过clang来分析c++ ...