Welcome, Guest! Sign Up RSS

Clever Space

Friday, 11.22.2024
Main » 2013 » September » 28 » [NOIP2012模拟赛No.4]买布
11:35 AM
[NOIP2012模拟赛No.4]买布

四平方和定理

#include<cstdio>
#include<cstdlib>
#include<cmath>
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
using namespace std;
int i,j,n;
int c1(int t){int R=(int)sqrt(t);return R*R==t;}
int c2(int t){FOR(i,1,(int)sqrt(t)) if (c1(t-i*i)) return 1;return 0;}
int c3(int t){FOR(j,1,(int)sqrt(t)) if (c2(t-j*j)) return 1;return 0;}
int main()
{
  scanf("%d",&n);
  if (c1(n)) {printf("1\n");return 0;}
  if (c2(n)) {printf("2\n");return 0;}
  if (c3(n)) {printf("3\n");return 0;}
  printf("4\n");
}

Views: 266 | Added by: dhy0077 | Rating: 5.0/1
Total comments: 0
Only registered users can add comments.
[ Sign Up | Login ]