zoukankan      html  css  js  c++  java
  • HDU3835

    ANS=0;

    if x*x+x*x==n ANS+=4;//( x,x)  (-x,-x) (-x,x)  (x,-x)

    if x*x+0*0==n ANS+=4;//(x,0)  (0,x)  (-x,0) (0,-x) 

    if a*a+b*b==n ANS+=8;

    View Code
     1 #include<stdio.h>
     2 #include<math.h>
     3 #include<string.h>
     4 const int maxn = 10005;
     5 int a[ maxn ];
     6 int main(){
     7     memset( a,0,sizeof(a));
     8     a[0]=1;
     9     for( int i=1;i<maxn;i++ ){
    10         int tmp=i/2;
    11         int now=1;
    12         while( now*now<tmp ){
    13             int sum=i-now*now;
    14             int tp=sqrt( sum*1.0 );
    15             if( tp*tp==sum ) a[ i ]+=8;
    16             now++;
    17         }
    18         if( (int)sqrt(i*1.0)*(int)sqrt(i*1.0)==i ) a[ i ]+=4;
    19         if( (int)sqrt(i*1.0)*(int)sqrt(i*1.0)*2==i ) a[ i ]+=4;
    20     }
    21     int n;
    22     while( scanf("%d",&n)==1 ){
    23         if( n<maxn ){
    24             printf("%d\n",a[ n ]);
    25             continue;
    26         }
    27         int ans=0;
    28         int i=n;
    29         int tmp=i/2;
    30         int now=1;
    31         while( now*now<tmp ){
    32             int sum=i-now*now;
    33             int tp=sqrt( sum*1.0 );
    34             if( tp*tp==sum ) ans+=8;
    35             now++;
    36         }
    37         if( (int)sqrt(i*1.0)*(int)sqrt(i*1.0)==i ) ans+=4;
    38         if( (int)sqrt(i*1.0)*(int)sqrt(i*1.0)*2==i ) ans+=4;
    39         printf("%d\n",ans);
    40     }
    41     return 0;
    42 }
    keep moving...
  • 相关阅读:
    mysql perl 抓取update语句
    $/ 改变换行符
    $/ 改变换行符
    java读取jpg图片旋转按比例缩放
    感应器
    lisp分支
    鸡肋的Drools
    postgre去重复记录
    拖拽到指定位置
    base64coder调用
  • 原文地址:https://www.cnblogs.com/xxx0624/p/2890344.html
Copyright © 2011-2022 走看看