UVALive 6862 Triples (找规律 暴力)
Triples
题目链接:
http://acm.hust.edu.cn/vjudge/contest/130303#problem/H
Description
http://7xjob4.com1.z0.glb.clouddn.com/4c05ed01e62e808388fc90e37554d588
Input
The input file contains several test cases, each of them as described below.
The first line contains the value of m and the second line contains the value of n.
Output
For each test case, the result will be written to standard output, on a line by itself.
Sample Input
```
85
95
```
Sample Output
```
8128
```
Source
2016-HUST-线下组队赛-4
##题意:
求有多少个三元组(x,y,z)满足 0
##题解:
由于n和m的数据都非常小,稍微打一下表就可以发现 j > 2 的时候不存在满足条件的三元组.
upd:实际上,上述表述为[费马大定理](http://baike.baidu.com/link?url=Ap0jvXEvOF9go2DTQ7LieopZRcrkcECDceCIu4VequB0IE9Bo3d8IC6gNq0yYnHmLDpfB9BQrWJRyS4xx8QYS9Yx7Lv0qJ_LvQifKep4zNe)
x=0时:y = z ∈ [0, m]. 故有 (m+1) * (n-1) 个解.
j=2时:暴力求一下即可.
##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long
#define maxn 101000
#define inf 0x3f3f3f3f
#define mod 1000000007
#define mid(a,b) ((a+b)>>1)
#define eps 1e-8
#define IN freopen("in.txt","r",stdin);
using namespace std;
int solve(int m) {
int cnt = 0;
for(LL i=1; i<=m; i++) {
for(LL j=i; j<=m; j++) {
LL x = ii + jj;
for(LL k=0; k<=m; k++) {
if(k*k == x) {
//printf("%d %d %d\n",i,j,k);
cnt++;
break;
}
}
}
}
return cnt;
}
int main()
{
//IN;
int m,n;
while(scanf("%d %d", &m,&n) != EOF)
{
int ans = solve(m) + (m+1)*(n-1);
printf("%d\n", ans);
}
return 0;
}
UVALive 6862 Triples (找规律 暴力)的更多相关文章
- UVaLive 6847 Zeroes (找规律,水题)
题意 :给定一个范围,然后让你求在这个范围内所有的数的阶乘末尾0的个数有多少种. 析:找规律,写几个就会发现每隔5个会增加一个0,因为要么乘10了,要么乘5了. 代码如下: #pragma comme ...
- UVaLive 6862 Triples (数学+分类讨论)
题意:给定一个n和m,问你x^j + y^j = z^j 的数量有多少个,其中0 <= x <= y <= z <= m, j = 2, 3, 4, ... n. 析:是一个数 ...
- 数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight
题目传送门 /* 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 */ #include <cstdio> #include <a ...
- SGU 107 987654321 problem【找规律】
题目链接: http://acm.sgu.ru/problem.php?contest=0&problem=107 题意: 平方后几位为987654321的n位数有多少个 分析: 虽然说是水题 ...
- 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用
转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...
- 找规律 UVALive 6506 Padovan Sequence
题目传送门 /* 找规律:看看前10项就能看出规律,打个表就行了.被lld坑了一次:( */ #include <cstdio> #include <algorithm> #i ...
- ACM_同余+暴力找规律
小光的忧伤 Time Limit: 2000/1000ms (Java/Others) Problem Description: 锴神:我尊重作者原意,你们出什么我就加什么.于是小光打了道水题(也就是 ...
- bzoj1002 轮状病毒 暴力打标找规律/基尔霍夫矩阵+高斯消元
基本思路: 1.先观察规律,写写画画未果 2.写程序暴力打表找规律,找出规律 1-15的答案:1 5 16 45 121 320 841 2205 5776 151 ...
- CF R 633 div 1 1338 C. Perfect Triples 打表找规律
LINK:Perfect Triples 初看这道题 一脸懵逼.. 完全没有思路 最多就只是发现一点小规律 即. a<b<c. 且b的最大的二进制位一定严格大于a b的最大二进制位一定等于 ...
随机推荐
- spring -boot定时任务 quartz 基于 MethodInvokingJobDetailFactoryBean 实现
spring 定时任务 quartz 基于 MethodInvokingJobDetailFactoryBean 实现 依赖包 如下 <dependencies> <depende ...
- Linux 查看CPU 核数 还有 CPU 个数的命令
cat /proc/cpuinfo | grep 'physical id' | sort | uniq | wc -l 个数 cat /proc/cpuinfo | grep 'process' | ...
- BSP中uboot初体验
一. uboot源码获取 1.1. 从板级厂家获取开发板BSP级uboot(就是由开发板厂家提供的) 1.2. 从SOC厂家获取相同SOC的BSP级uboot 1.3. 从uboot官方下载 1.4. ...
- dfs(最佳路径)
http://acm.hdu.edu.cn/showproblem.php?pid=1242 Rescue Time Limit: 2000/1000 MS (Java/Others) Memo ...
- seajs与requirejs
1 seajs暴露的两个对象 二 define()定义 引用模块 三插件 css插件和requirejs插件 4 seajs使用和建议
- iOS app被拒整理
作者:Leon链接:http://www.zhihu.com/question/33191327/answer/71421736来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...
- MySQL事务提交与回滚
提交 为了演示效果,需要打开两个终端窗口,使用同一个数据库,操作同一张表 step1:连接 终端1:查询商品分类信息 select * from goods_cates; step2:增加数据 终端2 ...
- 四、绑定SignaIR的用户管理
一.用户分组(第一个默认我的好友,禁删和更改) 没有分组id,更改layim代码: 更改id即可. layui.define('jquery', function (exports) { " ...
- 配置阿里云SLB全站HTTPS集群(以下内容仅为流程,信息可能有些对应不上)
1)登录阿里云购买两台实例 1.1) 按量付费购买两台实例 1.2) 配置网络可以不选择分配外网 1.3) 自定义密码 1.4) 购买完成 1.5) 实例列表 2)购买SLB实例 2.1)按量付费购买 ...
- Codeforces 959 树构造 暴力求最小字典序互质序列
A B C 题目给你一个结论 最少需要min((odd,even)个结点可以把一棵树的全部边连起来 要求你输出两颗树 一棵树结论是正确的 另外一棵结论是正确的 正确结论的树很好造 主要是错误的树 题目 ...