【BZOJ1041】[HAOI2008]圆上的整点【数学】
2016-03-28 20:25
381 查看
【题目链接】
奇怪的姿势。
【csyzcyj的题解】
/* Footprints In The Blood Soaked Snow */
#include <cstdio>
#include <cmath>
typedef long long LL;
LL R;
inline int gcd(LL a, LL b) {
for(; b; b ^= a ^= b ^= a %= b);
return a;
}
inline bool check(LL x, double y) {
if(y == (LL)y) {
LL y1 = (LL)y;
if(gcd(x * x, y1 * y1) == 1 && x != y1) return 1;
}
return 0;
}
int main() {
scanf("%lld", &R);
LL _2R = 2.0 * R, _sqrt2R = sqrt(_2R), ans = 0;
for(int d = 1; d <= _sqrt2R; d++)
if(_2R % d == 0) {
LL upb = sqrt(_2R / (2 * d));
for(int a = 1; a <= upb; a++) {
double b = sqrt(_2R / d - a * a);
if(check(a, b)) ans++;
}
if(d != _2R / d) {
LL upb = sqrt(d / 2);
for(int a = 1; a <= upb; a++) {
double b = sqrt(d - a * a);
if(check(a, b)) ans++;
}
}
}
printf("%lld\n", ans * 4 + 4);
return 0;
}
奇怪的姿势。
【csyzcyj的题解】
/* Footprints In The Blood Soaked Snow */
#include <cstdio>
#include <cmath>
typedef long long LL;
LL R;
inline int gcd(LL a, LL b) {
for(; b; b ^= a ^= b ^= a %= b);
return a;
}
inline bool check(LL x, double y) {
if(y == (LL)y) {
LL y1 = (LL)y;
if(gcd(x * x, y1 * y1) == 1 && x != y1) return 1;
}
return 0;
}
int main() {
scanf("%lld", &R);
LL _2R = 2.0 * R, _sqrt2R = sqrt(_2R), ans = 0;
for(int d = 1; d <= _sqrt2R; d++)
if(_2R % d == 0) {
LL upb = sqrt(_2R / (2 * d));
for(int a = 1; a <= upb; a++) {
double b = sqrt(_2R / d - a * a);
if(check(a, b)) ans++;
}
if(d != _2R / d) {
LL upb = sqrt(d / 2);
for(int a = 1; a <= upb; a++) {
double b = sqrt(d - a * a);
if(check(a, b)) ans++;
}
}
}
printf("%lld\n", ans * 4 + 4);
return 0;
}
相关文章推荐
- JavaScritpt的DOM初探之Node(一)
- 归园田居 东晋 陶渊明 注音版
- CentOS6 Shell脚本/bin/bash^M: bad interpreter错误解决方法
- 单行函数
- UVA 11090 图论加二分
- 2016年3月26日作业
- 最近对问题,分治法求解
- 借助SystemBarTint实现透明标题栏(沉浸式)
- adb相关问题
- a1005. Spell It Right (20)
- 堆排序
- Android Studio 2.1 Preview 4 发布,以及新增的两点攺动.
- 使用brew安装软件
- AOJ2249Contest Page(最短路径spfa)
- 送伞
- 数组指针和指针数组
- Win7下配置"JAVA环境变量"—JDK的安装与配置
- 数据库-T-SQL 语句-高级查询
- 程序员面试心得总结
- 【软件工程】复利计算程序单元测试