洛谷 p1625
高精度
我以为这题必有高论,怎么想也想不出来,没想到竟是如此粗鄙做法。
我们写一个高精度模拟一下,然后枚举约数看是否能约分,由于我不会高精度除法,就抄了一发
其实这种两项之比和项数有关的数列是不能推通项的,只能暴力模拟
#include<bits/stdc++.h>
using namespace std;
const int N = ;
int n, m;
struct Bigint {
int a[N], len;
Bigint friend operator + (Bigint &A, Bigint &B)
{
Bigint C;
memset(C.a, , sizeof(C.a));
int lim = max(A.len, B.len);
for(int i = ; i <= lim; ++i)
{
C.a[i] += A.a[i] + B.a[i];
C.a[i + ] += C.a[i] / ;
C.a[i] %= ;
}
C.len = lim;
if(C.a[lim + ]) ++C.len;
return C;
}
Bigint friend operator * (Bigint A, int x)
{
for(int i = ; i <= A.len; ++i) A.a[i] *= x;
for(int i = ; i <= A.len; ++i)
{
A.a[i + ] += A.a[i] / ;
A.a[i] %= ;
}
while(A.a[A.len + ] >= )
{
++A.len;
A.a[A.len + ] += A.a[A.len] / ;
A.a[A.len] %= ;
}
if(A.a[A.len + ] > ) ++A.len;
return A;
}
Bigint friend operator / (Bigint &A, int x)
{
Bigint B;
int tot = ;
memset(B.a, , sizeof(B.a));
for(int i = A.len; i; --i)
{
tot = tot * + A.a[i];
B.a[i] = tot / x;
tot %= x;
}
B.len = A.len;
while(B.a[B.len] == ) --B.len;
return B;
}
void print()
{
for(int i = len; i; --i) printf("%d", a[i]);
puts("");
}
} down, up, base;
bool can_div(Bigint &A, int x)
{
int tot = ;
for(int i = A.len; i; --i) tot = (tot * + A.a[i]) % x;
return (tot == );
}
int main()
{
scanf("%d%d", &n, &m);
down.len = ;
down.a[] = ;
base.len = ;
base.a[] = ;
for(int i = m + ; i < n + m; ++i) base = base * i;
for(int i = ; i <= n; ++i)
{
up = up + base;
base = base * i;
base = base / (m + i);
}
for(int i = ; i < n + m; ++i)
{
if(can_div(up, i)) up = up / i;
else down = down * i;
}
for(int i = ; i < n + m; ++i) if(can_div(up, i) && can_div(down, i))
{
up = up / i;
down = down / i;
}
up.print();
down.print();
return ;
}
洛谷 p1625的更多相关文章
- 洛谷1640 bzoj1854游戏 匈牙利就是又短又快
bzoj炸了,靠离线版题目做了两道(过过样例什么的还是轻松的)但是交不了,正巧洛谷有个"大牛分站",就转回洛谷做题了 水题先行,一道傻逼匈牙利 其实本来的思路是搜索然后发现写出来类 ...
- 洛谷P1352 codevs1380 没有上司的舞会——S.B.S.
没有上司的舞会 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description Ural大学有N个职员,编号为1~N.他们有 ...
- 洛谷P1108 低价购买[DP | LIS方案数]
题目描述 “低价购买”这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:“低价购买:再低价购买”.每次你购买一支股票,你必须用低于你上次购买它的价格购买它 ...
- 洛谷 P2701 [USACO5.3]巨大的牛棚Big Barn Label:二维数组前缀和 你够了 这次我用DP
题目背景 (USACO 5.3.4) 题目描述 农夫约翰想要在他的正方形农场上建造一座正方形大牛棚.他讨厌在他的农场中砍树,想找一个能够让他在空旷无树的地方修建牛棚的地方.我们假定,他的农场划分成 N ...
- 洛谷P1710 地铁涨价
P1710 地铁涨价 51通过 339提交 题目提供者洛谷OnlineJudge 标签O2优化云端评测2 难度提高+/省选- 提交 讨论 题解 最新讨论 求教:为什么只有40分 数组大小一定要开够 ...
- 洛谷P1371 NOI元丹
P1371 NOI元丹 71通过 394提交 题目提供者洛谷OnlineJudge 标签云端评测 难度普及/提高- 提交 讨论 题解 最新讨论 我觉得不需要讨论O long long 不够 没有取 ...
- 洛谷P1538迎春舞会之数字舞蹈
题目背景 HNSDFZ的同学们为了庆祝春节,准备排练一场舞会. 题目描述 在越来越讲究合作的时代,人们注意的更多的不是个人物的舞姿,而是集体的排列. 为了配合每年的倒计时,同学们决定排出——“数字舞蹈 ...
- 洛谷八月月赛Round1凄惨记
个人背景: 上午9:30放学,然后因为学校举办读书工程跟同学去书城选书,中午回来开始打比赛,下午又回老家,中间抽出一点时间调代码,回家已经8:50了 也许是7月月赛时“连蒙带骗”AK的太幸运然而因同学 ...
- 洛谷 P1379 八数码难题 Label:判重&&bfs
特别声明:紫书上抄来的代码,详见P198 题目描述 在3×3的棋盘上,摆有八个棋子,每个棋子上标有1至8的某一数字.棋盘中留有一个空格,空格用0来表示.空格周围的棋子可以移到空格中.要求解的问题是:给 ...
随机推荐
- 王垠:写给支持和反对《完全用Linux工作》的人们
王垠:写给支持和反对<完全用Linux工作>的人们 在一阵阵唾骂和欢呼声中,<完全用linux工作>被转载到了天涯海角.很多人支持我,也有很多人唾骂我.我不知道它是怎样流传到那 ...
- jupyter notebook的插件安装及文本格式修改
jupyter notebook的插件安装及文本格式修改 1.jupyter notebook拓展插件安装 启动jupyter notebook : 打开控制台输入命令 jupyter noteboo ...
- codeforces 689 Mike and Shortcuts(最短路)
codeforces 689 Mike and Shortcuts(最短路) 原题 任意两点的距离是序号差,那么相邻点之间建边即可,同时加上题目提供的边 跑一遍dijkstra可得1点到每个点的最短路 ...
- mySQL and sqoop for ubuntu
数据的导入导出 ——MySQL & sqoop in Ubuntu 1.完成搭建hadoop集群 2.安装MySQL sudo apt-get install mysql-server mys ...
- ZOJ 3684 Destroy
Destroy Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ID: 36 ...
- hdu 1853 KM算法
#include<stdio.h> #include<math.h> #include<string.h> #define N 200 #define inf 99 ...
- Javascript网址跳转方法
第一种: window.location.href="http://www.baidu.com"; 第二种: window.navigate("http://www.ba ...
- SVN提交时报错:Commit blocked by pre-commit hook (exit code 1) with no output.
可能的原因: 提交代码的SVN命令中,Comment长度短了.参考:http://tortoisesvn.net/docs/nightly/TortoiseSVN_en/tsvn-howto-minl ...
- Oracle RAC load blance
首先声明 本文基本是阅读 大话RAC 后的笔记.OK, 进入正题. Oracle 10g RAC中采取两种方式提供负载均衡.第一种是connection blance.在用户连接的时候,根据随机算法把 ...
- Redis: 改变HomeBrew安装的数据库文件目录
vi /usr/local/etc/redis.conf 修改dir "/Volumes/KG's Big YO/Documents/redis_data" 最后,启动Redis: ...