R(N)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1815    Accepted Submission(s): 929

Problem Description
We know that some positive integer x can be expressed as x=A^2+B^2(A,B are integers). Take x=10 for example, 
10=(-3)^2+1^2.
We define R(N) (N is positive) to be the total number of variable presentation of N. So R(1)=4, which consists of 1=1^2+0^2, 1=(-1)^2+0^2, 1=0^2+1^2, 1=0^2+(-1)^2.Given N, you are to calculate R(N).
 
Input
No more than 100 test cases. Each case contains only one integer N(N<=10^9).
 
Output
For each N, print R(N) in one line.
 
Sample Input
2
6
10
25
65
 
Sample Output
4
0
8
12
16

Hint

For the fourth test case, (A,B) can be (0,5), (0,-5), (5,0), (-5,0), (3,4), (3,-4), (-3,4), (-3,-4), (4,3) , (4,-3), (-4,3), (-4,-3)

 
Source
 
Recommend
xubiao   |   We have carefully selected several similar problems for you:  3833 3834 3832 3831 3830 

 
  水题,数学题
  题意是求一个正整数N分解成 N=A^2+B^2 的形式有多少种。A、B可以从0开始。
  思路:遍历即可,注意两层循环会超时,尽量用一层循环。用cin、cout不会超时。
  代码:
 #include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std; int main()
{
int n;
while(scanf("%d",&n)!=EOF){
int sum = ;
for(int i=;i<=sqrt(n);i++){
int j = n-i*i;
double t = sqrt(j);
if(t-int(t)==){ //开方成功
if(i!= && j!=)
sum+=;
else if(i== || j==)
sum+=;
}
}
printf("%d\n",sum);
}
return ;
}

Freecode : www.cnblogs.com/yym2013

hdu 3835:R(N)(水题,数学题)的更多相关文章

  1. HDU 4950 Monster (水题)

    Monster 题目链接: http://acm.hust.edu.cn/vjudge/contest/123554#problem/I Description Teacher Mai has a k ...

  2. HDU 4593 H - Robot 水题

    H - RobotTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...

  3. hdu 1106:排序(水题,字符串处理 + 排序)

    排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...

  4. HDU 4813 Hard Code 水题

    Hard Code Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...

  5. HDOJ/HDU 2560 Buildings(嗯~水题)

    Problem Description We divide the HZNU Campus into N*M grids. As you can see from the picture below, ...

  6. HDOJ(HDU) 1859 最小长方形(水题、、)

    Problem Description 给定一系列2维平面点的坐标(x, y),其中x和y均为整数,要求用一个最小的长方形框将所有点框在内.长方形框的边分别平行于x和y坐标轴,点落在边上也算是被框在内 ...

  7. HDU - 1716 排列2 水题

    排列2 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  8. HDU—2021-发工资咯(水题,有点贪心的思想)

    作为杭电的老师,最盼望的日子就是每月的8号了,因为这一天是发工资的日子,养家糊口就靠它了,呵呵  但是对于学校财务处的工作人员来说,这一天则是很忙碌的一天,财务处的小胡老师最近就在考虑一个问题:如果每 ...

  9. HDU 3835 R(N)

    R(N) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

随机推荐

  1. 运用Unity实现AOP拦截器[结合异常记录实例]

      本篇文章将通过Unity实现Aop异常记录功能:有关Unity依赖注入可以看前两篇文章: 1:运用Unity实现依赖注入[结合简单三层实例] 2:运用Unity实现依赖注入[有参构造注入] 另早期 ...

  2. lshw-查看系统硬件信息

    lshw是系统日常使用会比较常用到的命令,一般是用它来查看新硬件的信息. 跟觉man,lshw会读取的文件有: /usr/local/share/pci.ids /usr/share/pci.ids ...

  3. [Exception Android 22] - Could not find com.android.support:design:23.1.1

    Error:A problem occurred configuring project ':app'. > A problem occurred configuring project ':f ...

  4. ECMAScript6 | 新特性(部分)

    新特性概览 参考文章:http://www.cnblogs.com/Wayou/p/es6_new_features.html 这位前辈写的很好,建议深入学习 ———————————————————— ...

  5. Hibernate的批量操作

    在实际的操作中,会经常的遇到批量的操作,使用hibernate将 100条记录插入到数据库的一个很自然的做法可能是这样的 Session session = sessionFactory.openSe ...

  6. 基于Python-Flask实现的网站例子

    概述 使用Flask写的体育网站 包括(注册 论坛 文章评论 组建战队 后台管理)等功能 示例地址文中有写 萌新 请多指教 详细 代码下载:http://www.demodashi.com/demo/ ...

  7. MySQL-group-replication 配置

    MySQL-Group-Replication 是mysql-5.7.17版本开发出来的新特性:它在master-slave 之间实现了强一致性, 但是就目前来说主要是性能不太好. [1]确定当前的m ...

  8. 调试JDK1.8源码的方法

    背景 在学习JDK源码的时候,免不了需要调试JDK的源码. 比如:想理解ConcurrentHashMap的put(K k, V v)方法,JDK自带的rt.jar文件是支持断点调试,但是却看不到变量 ...

  9. TypesMethodsAndFields

    https://github.com/JesusFreke/smali/wiki/TypesMethodsAndFields Types dalvik's bytecode has two major ...

  10. Android4.4的zygote进程(下)

    3.2.4启动Android系统服务——startSystemServer() 接下来就是启动Android的重头戏了,此时ZygoteInit的main()函数会调用startSystemServe ...