UVA 12576 - Simply Loopy
来源:互联网 发布:夜猫子软件 编辑:程序博客网 时间:2024/04/29 06:43
简述:给定N,求 x1 + x2 + x3 + x4 + x5 = N的所有非负整数解的平方和。
思路:先求 x1 的所有解的平方和。当 x1 = k,x2 + x3 + x4 + x5 = N - k的非负整数解个数为C(N-k-1,3),产生了 k*k*C(N-k-1,3) 这么多值。当 k 取遍 1,2...N-4 时,x1 这个位置上的解就求完了。然后根据轮转对称性,x2 , x3 , x4 , x5 都应该产生了这么多值。
贴在这里不是因为难,是自认为思路不错。
#include<iostream>#include<algorithm>#include<cstdio>#include<cstdlib>#include<cstring>#include <cmath>#define LL long long#define eps (1e-8)#define clr(A) memset(A,0,sizeof(A))using namespace std;int const mod = 7477777;int const maxn = 100005;int f[maxn],c[maxn];int main(){ int T,cnt = 0; for(int i = 1;i<maxn;i++) { f[i] = ((LL)i*i) % mod; c[i] = (LL)i*(i-1)*(i-2)/6 % mod; } scanf("%d",&T); while(T--) { int n; scanf("%d",&n); if(n<5) {printf("Case %d: 0\n",++cnt);continue;} int ret = 0; for(int i = 1; i <= n-4; i++) { ret = ((LL)f[i]*c[n-i-1]+ret) % mod; } printf("Case %d: %d\n",++cnt,ret*5 % mod); } return 0;}
0 0
- UVA 12576 - Simply Loopy
- UVA 12576 Simply Loopy
- Uva 10235 - Simply Emirp
- UVa 10235 - Simply Emirp
- UVa 496 - Simply Subsets
- UVa 496 Simply Subsets (STL&set_intersection)
- loopy belief propagaton
- Simply JavaScript
- Max-Product Loopy Belief Propagation
- UVa 10140 - Prime Distance
- UVA 321 - The New Villa
- UVA 10422 - Knights in FEN
- UVA 705 - Slash Maze
- loopy()代表什么意思,怎么用
- Simply memorize sth
- Simply Rails 2 [ILLUSTRATED]
- POJ1126 Simply Syntax (递归)
- poj 1126 Simply Syntax
- 计算机原理学习(7)-- x86-32 CPU和内存管理之分段管理
- ios7隐藏状态栏
- Java动态绑定机制的内幕
- 为什么有堆内存栈内存之分
- jsonp跨域请求
- UVA 12576 - Simply Loopy
- ipv4理论知识1-ipv4介绍,ipv4记法,地址段个数算法
- 第七章 F# 库(三)
- Treap小解析(Part 1 of 2)
- 通过wifi调试android程序
- 新手学python(3):yield与序列化
- android 应用商城注册
- 斐波那契堆
- java 中线程的实现方式的比较