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. 滚动锁定 scroll lock 键有什么用?

    滚动锁定 scroll lock 键有什么用? 中文名称:滚动锁定键  按下此键后在Excel等按上.下键滚动时,会锁定光标而滚动页面:如果放开此键,则按上.下键时会滚动光标而不滚动页面.      ...

  2. Cannot make a static reference to the non-static method的解决方法

    报错原因:在一个类中写了一个public String getContent()方法和一个main()方法,getContent()方法中包含了getClass()方法,在main()方法中直接调用了 ...

  3. 【Statistics】均值

    均值 均值(mean)是全部数据的算术平均值,也称为算术平均.在统计学中具有重要的地位,是集中趋势的主要测量值.均值分为:简单均值.加权均值. 简单均值 设代表均值,代表样本各变量值,n代表变量个数, ...

  4. Python-PyQt4学习笔记

    1.每个应用必须创建一个 QtGui.QApplication(sys.argv), 此时 QtGui.qApp 为此应用的实例 app = QtGui.QApplication(sys.argv) ...

  5. Android实现换肤功能(一)

    上周有个朋友给建议说讲讲换肤吧,真巧这周公司的工作安排也有这个需求,换的地方之多之繁,让人伤神死了.正所谓磨刀不误砍柴工,先磨下刀,抽出一个工具类,写了个关于换肤的简单demo. Android中换肤 ...

  6. 安装 Tomcat

    安装 Tomcat(.exe)  而 .rar文件则只需解压即可使用. 点击 apache-tomcat-7.0.55.exe 进行安装: 在“Configuration”: Server Shutd ...

  7. 在做和sap系统集成的一点心得

    最这一个月和sap做集成,把主数据中的数据写入到sap系统中,做集成就离不开联调,平时开发中,一个复杂点的系统还容易出问题,涉及到两个系统,由于两个或多个系统来自不同的厂家,各个厂家的开发对业务的理解 ...

  8. C# 取时间段年、月、日、季度

    DateTime dt = DateTime.Now;  //当前时间             DateTime startWeek = dt.AddDays(1 - Convert.ToInt32( ...

  9. PHP保留2位小数、格式化小数、浮点数

    JS保留两位小数例子 四舍五入使用函数 toFixed() [javascript] <html> <head> </head> <script> va ...

  10. [svc][op]如何查看当前Ubuntu系统的版本

    如何查看当前Ubuntu系统的版本 说来也惭愧,用Ubuntu差不多快1个月了,双系统是让朋友安的,只知道自己使用的是什么12版本的,具体怎么看还不知道,下面写一下查看当前Linux系统的版本的方法 ...