51nod 1165 整边直角三角形的数量
第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 50000)
第2 - T + 1行:每行1个数N(12 <= N <= 10^7)。
输出共T行,每行1个对应的数量。
2
120
13
3
0 题意:问有多少种直角三角形的周长恰好为n
分析:
假设a<b<c
a+b+c=n
a^2+b^2=c^2
c = sqrt(a^2+b^2)
c=n-(a+b)
c^2 = a^2+b^2 = (n-(a+b))^2
a^2+b^2 = n^2 - 2*(a+b)*n + a^2 + b^2 + 2*a*b
2*(a+b)*n = n^2 + 2*a*b
2*n*b - 2*a*b = n^2 - 2*m*a
b = (n^2 - 2*n*a) / (2*n - 2*a)
设 t = n-a
b = (2*(n^2 - n*a) - n^2) / 2*(n-a)
= n - n^2/(2*t) 因为 t = n-a, a < b < c, a+b > c, c < n/2
所以 n-t = a < b = n- n^2/(2*t)
n^2/(2*t) < t
n^2 < 2*t^2
2*t > sqrt(2)*n t < n 所以 sqrt(2)*n < 2*t < 2*n 所以,只需要找出n的所有因数,把它们个数*2,就是L^2因数的个数
然后枚举每个因数多少个(注意,2*t显然是2的倍数),记一下在那个范围里面的个数,即为答案 下面上代码
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
using namespace std;
typedef long long LL;
typedef double DB;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair
inline void SetIO(string Name) {
string Input = Name+".in",
Output = Name+".out";
freopen(Input.c_str(), "r", stdin),
freopen(Output.c_str(), "w", stdout);
} const int N = , M = ;
int Prime[M], Tot;
bool Visit[N];
int n;
int Factor[M], Num[M], Len;
int Left, Right, Answer[N], Ans; inline void GetPrime() {
For(i, , N-) {
if(!Visit[i]) Prime[++Tot] = i;
For(j, , Tot) {
if(i*Prime[j] >= N) break;
Visit[i*Prime[j]] = ;
if(!(i%Prime[j])) break;
}
}
} inline void Solve(); inline void Input() {
GetPrime(); int TestNumber;
scanf("%d", &TestNumber);
while(TestNumber--) {
scanf("%d", &n);
Solve();
}
} inline void GetFactor(int x) {
For(i, , Tot) {
if(x == || Prime[i] > x) break;
if(!(x%Prime[i])) {
Len++;
Factor[Len] = Prime[i], Num[Len] = ;
while(!(x%Prime[i])) x /= Prime[i], Num[Len]++;
}
} if(x > ) {
Len++;
Factor[Len] = x, Num[Len] = ;
}
} LL Temp;
inline void Search(int x, int Val) {
if(Left < Val && Val < Right && !(Val%)) Answer[++Ans] = Val;
if(x > Len || Val >= Right) return; int Cnt = ;
For(i, , Num[x]) {
Search(x+, Val*Cnt);
if(Val*Cnt >= Right/Factor[x]) break;
Cnt *= Factor[x];
}
} inline void Solve() {
if(n&) {
puts("");
return;
} Len = ;
GetFactor(n);
For(i, , Len) Num[i] <<= ; Ans = ;
Left = n*sqrt(), Right = *n;
Search(, ); sort(Answer+, Answer++Ans);
int p = ;
For(i, , Ans)
if(Answer[p] != Answer[i]) Answer[++p] = Answer[i];
/*For(i, 1, p) {
int b = n-n*n/Answer[i];
int a = n-Answer[i]/2;
int c = n-a-b;
printf("%d %d %d %d\n", Answer[i], a, b, c);
}*/
printf("%d\n", p);
} int main() {
#ifndef ONLINE_JUDGE
SetIO("");
#endif
Input();
//printf("%d\n", Tot);
//Solve();
return ;
}
51nod 1165 整边直角三角形的数量的更多相关文章
- 51nod 1165 整边直角三角形的数量(两种解法)
链接:http://www.51nod.com/Challenge/Problem.html#!#problemId=1165 直角三角形,三条边的长度都是整数.给出周长N,求符合条件的三角形数量. ...
- 51Nod 1003 阶乘后面0的数量(数学,思维题)
1003 阶乘后面0的数量 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 n的阶乘后面有多少个0? 6的阶乘 = 1*2*3*4*5*6 = 720 ...
- pku 1401 Factorial 算数基本定理 && 51nod 1003 阶乘后面0的数量
链接:http://poj.org/problem?id=1401 题意:计算N!的末尾0的个数 思路:算数基本定理 有0,分解为2*5,寻找2*5的对数,2的因子个数大于5,转化为寻找因子5的个数. ...
- 51Nod 1003 阶乘后面0的数量 | 思维
题意:n的阶乘后面0的个数,如果直接算出阶乘再数0的数量一定会超时的. 因为10=2*5,所以求出5贡献的次数就行. #include "bits/stdc++.h" using ...
- 【51nod 1251】 Fox序列的数量(以及带限制插板法讲解)
为什么网上没有篇详细的题解[雾 可能各位聚聚觉得这道题太简单了吧 /kk 题意 首先题目是求满足条件的序列个数,条件为:出现次数最多的数仅有一个 分析 感谢 刚睡醒的 JZ姐姐在咱写题解忽然陷入自闭的 ...
- @51nod - 1196/1197/1198@ 字符串的数量
目录 @description@ @solution@ @part - 1@ @part - 2@ @part - 3@ @accepted code@ @details@ @description@ ...
- 51nod 1009:数字1的数量
1009 数字1的数量 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 收藏 关注 给定一个十进制正整数N,写下从1开始,到N的所有正数,计算出其中出现所有1的个 ...
- 51nod 1003 阶乘后面0的数量
每一个 2 与一个 5 相乘,结果就增加一个零. 所以求 n! 后面的连续零的个数,其实就是求其中相乘的数含有因子每对因子 2 与 5 的个数. 又因为从1到某个数,所含 2 的个数比 5 多,所以 ...
- 【51nod】1251 Fox序列的数量
题解 容斥题 我们枚举出现次数最多的数出现了K次 然后我们需要计算的序列是所有数字出现个数都不超过K - 1次 我们枚举不合法的数字的数目j,说明这个排列里除了我们固定出现K次的数至少有j个数是不合法 ...
随机推荐
- java笔记--查看和修改线程名称
查看和修改线程名称 --如果朋友您想转载本文章请注明转载地址"http://www.cnblogs.com/XHJT/p/3893797.html "谢谢-- java是一种允许 ...
- 【转】使用genstring和NSLocalizedString实现App文本的本地化
原地址:http://www.cnblogs.com/U-tansuo/p/IOS_NSLocalizedString.html iOS提供了简便的方法来实现本地化,其中用的最多的就是NSLocali ...
- The Flash
flash.now[:error] = "" render :new flash[:error] = "" redirect videos_path http: ...
- ubuntu下git输出的颜色变化
(这些文章都是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) 11点进家门,感觉很温暖哦. 以下是如何在用git的时候清晰的看出关键字的方法. $ vim ...
- Coursera台大机器学习技法课程笔记03-Kernel Support Vector Machine
这一节讲的是核化的SVM,Andrew Ng的那篇讲义也讲过,讲的也不错. 首先讲的是kernel trick,为了简化将低维特征映射高维特征后的计算,使用了核技巧.讲义中还讲了核函数的判定,即什么样 ...
- BZOJ 1058
服气!我果然就是个傻逼. 傻兮兮地感觉两个数之间的差距无需删除一些答案,妈个鸡就只加入了一些新的答案忘记了去掉无效的答案.我果然是傻逼,经验不足脑子笨... 这么水的题...不说了,说多了都是泪. 自 ...
- 二模 06day2
很长时间没更新有意义的题目了呢,这是一套题撒,于是乎我便开心的边刷题边发题解了撒. 第一题: interval 比较好玩的一题撒, 分分钟过了, 就是模拟贪吃蛇但是没有食物(嗯,只要你判断冲突). 整 ...
- Android app主线程UI更新间歇性崩溃的问题
对App进行开发测试时,偶尔出现app崩溃的问题.日志如下: 10-25 18:44:52.935 15290-15290/com.zzq.cnblogs E/AndroidRuntime﹕ FATA ...
- 1.saltstack基础笔记
环境: master: 节点node1:阿里云:121.42.195.15 centos6.6 minion: 节点node2:腾讯云:182.254.157.19 centos6.6 一.salts ...
- codeforces B. Sereja and Stairs 解题报告
题目链接:http://codeforces.com/problemset/problem/381/B 题目意思:给定一个m个数的序列,需要从中组合出符合楼梯定义 a1 < a2 < .. ...