高精度

我以为这题必有高论,怎么想也想不出来,没想到竟是如此粗鄙做法。

我们写一个高精度模拟一下,然后枚举约数看是否能约分,由于我不会高精度除法,就抄了一发

其实这种两项之比和项数有关的数列是不能推通项的,只能暴力模拟

#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的更多相关文章

  1. 洛谷1640 bzoj1854游戏 匈牙利就是又短又快

    bzoj炸了,靠离线版题目做了两道(过过样例什么的还是轻松的)但是交不了,正巧洛谷有个"大牛分站",就转回洛谷做题了 水题先行,一道傻逼匈牙利 其实本来的思路是搜索然后发现写出来类 ...

  2. 洛谷P1352 codevs1380 没有上司的舞会——S.B.S.

    没有上司的舞会  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond       题目描述 Description Ural大学有N个职员,编号为1~N.他们有 ...

  3. 洛谷P1108 低价购买[DP | LIS方案数]

    题目描述 “低价购买”这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:“低价购买:再低价购买”.每次你购买一支股票,你必须用低于你上次购买它的价格购买它 ...

  4. 洛谷 P2701 [USACO5.3]巨大的牛棚Big Barn Label:二维数组前缀和 你够了 这次我用DP

    题目背景 (USACO 5.3.4) 题目描述 农夫约翰想要在他的正方形农场上建造一座正方形大牛棚.他讨厌在他的农场中砍树,想找一个能够让他在空旷无树的地方修建牛棚的地方.我们假定,他的农场划分成 N ...

  5. 洛谷P1710 地铁涨价

    P1710 地铁涨价 51通过 339提交 题目提供者洛谷OnlineJudge 标签O2优化云端评测2 难度提高+/省选- 提交  讨论  题解 最新讨论 求教:为什么只有40分 数组大小一定要开够 ...

  6. 洛谷P1371 NOI元丹

    P1371 NOI元丹 71通过 394提交 题目提供者洛谷OnlineJudge 标签云端评测 难度普及/提高- 提交  讨论  题解 最新讨论 我觉得不需要讨论O long long 不够 没有取 ...

  7. 洛谷P1538迎春舞会之数字舞蹈

    题目背景 HNSDFZ的同学们为了庆祝春节,准备排练一场舞会. 题目描述 在越来越讲究合作的时代,人们注意的更多的不是个人物的舞姿,而是集体的排列. 为了配合每年的倒计时,同学们决定排出——“数字舞蹈 ...

  8. 洛谷八月月赛Round1凄惨记

    个人背景: 上午9:30放学,然后因为学校举办读书工程跟同学去书城选书,中午回来开始打比赛,下午又回老家,中间抽出一点时间调代码,回家已经8:50了 也许是7月月赛时“连蒙带骗”AK的太幸运然而因同学 ...

  9. 洛谷 P1379 八数码难题 Label:判重&&bfs

    特别声明:紫书上抄来的代码,详见P198 题目描述 在3×3的棋盘上,摆有八个棋子,每个棋子上标有1至8的某一数字.棋盘中留有一个空格,空格用0来表示.空格周围的棋子可以移到空格中.要求解的问题是:给 ...

随机推荐

  1. Luogu P2176 [USACO14FEB]路障Roadblock

    解题思路 这是一道最短路题目,不知道大家有没有做过玛丽卡这道题目,如果没做,在做完这道题之后可以去拿个双倍经验哦 先求出一张图中的最短路径,并将其记录下来,我们首先思考:要有增量的前提是新的最短路径比 ...

  2. centos7+VMware Workstation创建共享文件夹

    1.第一步设置宿主机共享文件夹路径 2.挂载VMware Tools,如下操作会将tools以光盘挂载点的方式进入到系统中. 3.centos7 挂载存有VMware Tools的光盘并进行安装 1) ...

  3. FileOutputStream将从一个文件中读取的内容写到另一个文件中

    package com.janson.day2018082 import java.io.FileInputStream; import java.io.FileNotFoundException; ...

  4. iframe使用大全

    <iframe src=”you page’s url” width=”100″ height=”30″ frameborder=”no” border=”0″ marginwidth=”0″ ...

  5. idea 如何将本地代码上传到github

    1. 首先切换到项目根目录下 执行 git init 2. 点击项目右键->Git->Repository->Remotes->编辑URL 到github代码地址.

  6. Spring使用DriverManagerDataSource和C3P0分别配置MySql6.0.6数据源

    首先,看一下项目路径 先说spring配置文件吧,这个比较重要 <?xml version="1.0" encoding="UTF-8"?> < ...

  7. session 与 cookie 区别-----https://segmentfault.com/a/1190000013447750?utm_source=tag-newest

    cookie数据存放在客户的浏览器上,session数据放在服务器上. cookie不是很安全,别人可以分析存放在本地的COOKIE并进行COOKIE欺骗考虑到安全应当使用session. sessi ...

  8. Spark在Executor上的内存分配

    spark.serializer (default org.apache.spark.serializer.JavaSerializer )    建议设置为 org.apache.spark.ser ...

  9. [bzoj 1093][ZJOI2007]最大半联通子图(强联通缩点+DP)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1093 分析: 首先肯定是先把强联通全部缩成一个点,然后成了一个DAG 下面要知道一点: ...

  10. apache2 ubuntu18.04 配置虚拟端口

    修改3个文件/etc/apache2/apache2.conf/etc/apache2/ports.conf/etc/apache2/sites-available/000-default.conf ...