SOJ-1012
来源:互联网 发布:ps统一肤色软件 编辑:程序博客网 时间:2024/04/29 16:58
/****************************************************************************************************** ** Copyright (C) 2011.05.01 - 2013.07.01 ** Author: famousDT <13730828587@163.com> ** Edit date: 2011-04-25******************************************************************************************************/#include <stdio.h>#include <stdlib.h>//abs,atof(string to float),atoi,atol,atoll#include <math.h>//atan,acos,asin,atan2(a,b)(a/b atan),ceil,floor,cos,exp(x)(e^x),fabs,log(for E),log10#include <vector>#include <queue>#include <map>#include <set>#include <string>#include <iostream>#include <string.h>//memcpy(to,from,count#include <ctype.h>//character process:isalpha,isdigit,islower,tolower,isblank,iscntrl,isprint#include <algorithm>using namespace std;//typedef long long int ll;#define PI acos(-1)#define MAX(a, b) ((a) > (b) ? (a) : (b))#define MIN(a, b) ((a) < (b) ? (a) : (b))#define MALLOC(n, type) ((type *)malloc((n) * sizeof(type)))#define FABS(a) ((a) >= 0 ? (a) : (-(a)))#define MAXN 1000000int flag[MAXN + 5];int ans;int gcd(int a, int b){ return b == 0 ? a : gcd(b, a % b);}void process(int value){ int i, j; for (j = 1; j * j <= value; ++j) { int minj = MIN(sqrt(value - j * j) + 1, j - 1); for (i = 1; i <= minj; ++i) { if (gcd(i, j) == 1) { int x = j * j - i * i; int y = 2 * i * j; int z = j * j + i * i; if (x <= value && y <= value && z <= value) { if (gcd(gcd(x, y), z) == 1) ++ans; } else break; int times = 1; while (x * times <= value && y * times <= value && z * times <= value) { flag[x * times] = flag[y * times] = flag[z * times] = 1; ++times; } } } }}int main(){ int n; while (cin>>n) { ans = 0; memset(flag, 0, sizeof(int)); int i; int sum = 0; process(n); for (i = 0; i <= n; ++i) if (flag[i]) ++sum; printf("%d %d\n", ans, n -sum); } return 0;}
- SOJ-1012
- SOJ 1012
- SOJ 1012 Stacking Cylinders
- soj
- soj 1814
- SOJ-1013
- SOJ-1015
- SOJ-1016
- SOJ-3327
- soj 3109
- { }soj.1206
- { }soj.2013
- SOJ-Dollars
- soj 1715
- soj 1681
- soj 6099
- soj 1050
- SOJ 13984
- 诺基亚N950–MeeGo式体验
- EasyFliow- Process ID错误处理方法大全
- SOJ-1008(将LCA问题转化为RMQ)
- Unity3D第三人称镜头脚本 可旋转,拉近
- 深入理解缓冲区(十六)
- SOJ-1012
- SOJ-1013
- SOJ-1015
- HttpServletRequest
- SOJ-1016
- SOJ-3327
- Servlet 乱码问题 及 图片下载
- BlueStacks再获640万美元投资,让Android应用运行在Windows设备上
- 从github中取android的sourcecode