UVALive 6176 Faulhaber's Triangle C++大数模拟
来源:互联网 发布:qq刷钻软件下载 编辑:程序博客网 时间:2024/06/05 03:01
题目链接:点击打开链接
大数模拟
#include <cstdio>#include <cstring>#include <cmath>#include <queue>#include <map>#include <set>#include <stack>#include <iostream>#include <algorithm>using namespace std;typedef long long ll;const int N = 450;struct node {ll x, y;void print() {if (y == 1 || x == 0)printf("%lld", x);elseprintf("%lld/%lld", x, y);puts("");}void repair() {if (x != 0) {ll c = __gcd(x, y);x /= c;y /= c;}if (x == 0)y = 1;if (y < 0) {x = -x;y = -y;}}node() {x = 0;y = 1;}};node a[N][N], one, sum[N];node sub(node i, node j) {node re;ll c = i.y / __gcd(i.y, j.y) * j.y;i.x = c / i.y * i.x;j.x = c / j.y * j.x;re.x = i.x - j.x;re.y = c;re.repair();return re;}node add(node i, node j) {node re;ll c = i.y / __gcd(i.y, j.y) * j.y;i.x = c / i.y * i.x;j.x = c / j.y * j.x;re.x = i.x + j.x;re.y = c;re.repair();return re;}int main() {one.x = 1;for (int i = 0; i <= 400; ++i) {a[i][1] = sub(one, sum[i]);int k = 1;for (int j = i + 1; j <= 410; ++j) {++ k;a[j][k] = a[j - 1][k - 1];a[j][k].x *= j;a[j][k].y *= k;a[j][k].repair();sum[j] = add(sum[j], a[j][k]);}}int cas, n, m;scanf("%d", &cas);while (cas -- > 0) {scanf("%d", &n);printf("%d ", n);scanf("%d%d", &n, &m);a[n][m].print();}return 0;}
0 0
- UVALive 6176 Faulhaber's Triangle C++大数模拟
- hdu4488 Faulhaber’s Triangle(模拟)
- Uva 6176 Faulhaber's Triangle
- hdu4488 Faulhaber’s Triangle(模拟题)
- hdu4488 Faulhaber’s Triangle
- HDU 4488Faulhaber’s Triangle(模拟 题目有公式)
- hdu 4488 Faulhaber’s Triangle
- hdu 4488 Faulhaber’s Triangle
- HDU 4488 Faulhaber’s Triangle
- HDU 4488 Faulhaber’s Triangle (数学题)
- Leetcode 118 - Pascal's Triangle(模拟)
- SGU 476 Coach's Trouble 大数模拟
- [C++]LeetCode: 7 Pascal's Triangle
- [C++]LeetCode: 8 Pascal's Triangle II
- [leetcode-118]Pascal's Triangle(c++)
- [leetcode-119]Pascal's Triangle II (c++)
- 【leetcode c++】118 Pascal's Triangle
- [C语言][LeetCode][118]Pascal's Triangle
- UVALive 6174 Pen Counts 规律
- 一道面试题 不用long的相关api将数字字符串转换成long
- UVALive 6175 Maximum Random Walk 期望+概率dp
- 在菜单Setting加入子菜单
- Hdu-5050 Divided Land(Java高精度)
- UVALive 6176 Faulhaber's Triangle C++大数模拟
- activity切换动画效果
- HDU 5046 Airport DLX
- 安卓内部下载
- 使用Xcode 5创建(静态库)--Good
- Activity绑定service
- Java虚拟机工作原理详解
- IntentService
- [WHY] 一些编程相关的分享