(hdu 简单题 128道)平方和与立方和(求一个区间的立方和和平方和)

题目:

平方和与立方和

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 108212    Accepted Submission(s): 34915

Problem Description

给定一段连续的整数,求出他们中所有偶数的平方和以及所有奇数的立方和。

Input

输入数据包含多组测试实例,每组测试实例包含一行,由两个整数m和n组成。

Output

对于每组输入数据,输出一行,应包括两个整数x和y,分别表示该段连续的整数中所有偶数的平方和以及所有奇数的立方和。
你可以认为32位整数足以保存结果。

Sample Input

1 3
2 5

Sample Output

4 28
20 152

Author

lcy

Source

C语言程序设计练习(一)

题目分析:

简单题。

代码如下:

/*
 * c.cpp
 *
 *  Created on: 2015年3月20日
 *      Author: Administrator
 */

#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
	int a,b;
	while(scanf("%d%d",&a,&b)!=EOF){
		double ans_ji = 0;
		double ans_ou = 0;
		int i;

		//这道题需要注意一下的就是要考虑b<a的情况
		if(b < a){
			swap(a,b);
		}
		for(i = a ; i <= b ; ++i){
			if(i % 2 == 1){
				ans_ji += pow(i+0.0,3);
			}else{
				ans_ou += pow(i+0.0,2);
			}
		}

		printf("%d %d\n",(int)ans_ou,(int)ans_ji);
	}

	return 0;
}
时间: 2024-10-24 20:37:30

(hdu 简单题 128道)平方和与立方和(求一个区间的立方和和平方和)的相关文章

(hdu 简单题 128道)AC Me(统计一行文本中各个字母出现的次数)

题目: AC Me Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13465    Accepted Submission(s): 5927 Problem Description Ignatius is doing his homework now. The teacher gives him some articles and as

(hdu 简单题 128道)Lowest Bit(求一个数的二进制的最后一个非零位对应的十进制数)

题目: Lowest Bit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8722    Accepted Submission(s): 6428 Problem Description Given an positive integer A (1 <= A <= 100), output the lowest bit of A.

(hdu 简单题 128道)hdu 1194 Beat the Spread!(已知两个数的和u两个数的差求这两个数)

题目: Beat the Spread! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5169    Accepted Submission(s): 2692 Problem Description Superbowl Sunday is nearly here. In order to pass the time waiting f

(hdu 简单题 128题)hdu 2005 第几天(计算当天是该年的第几天)

题目: 第几天? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 89641    Accepted Submission(s): 33727 Problem Description 给定一个日期,输出这个日期是该年的第几天. Input 输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,

(数位DP 1.1)hdu 2089 不要62(求一个区间[a,b]中不包含4,64的数的个数)

题目: 不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 23759    Accepted Submission(s): 8128 Problem Description 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来

(hdu step 1.2.8)Specialized Four-Digit Numbers(求一个数字各个数位上数字的和)

题目: Specialized Four-Digit Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2027 Accepted Submission(s): 1349   Problem Description Find and list all four-digit numbers in decimal notation

hdu 1201 18岁生日 (简单题)

18岁生日 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 18281    Accepted Submission(s): 5776 Problem Description Gardon的18岁生日就要到了,他当然很开心,可是他突然想到一个问题,是不是每个人从出生开始,到达18岁生日时所经过的天数都是一样的呢?似乎并不全都是这样,所以他

HDU 1025 Constructing Roads In JGShining&#39;s Kingdom   LIS 简单题 好题 超级坑

Constructing Roads In JGShining's Kingdom Problem Description JGShining's kingdom consists of 2n(n is no more than 500,000) small cities which are located in two parallel lines. Half of these cities are rich in resource (we call them rich cities) whi

HDU 1316 How Many Fibs?(java,简单题,大数)

题目 /** * compareTo:根据该数值是小于.等于.或大于 val 返回 -1.0 或 1: public int compareTo(BigInteger val) 将此 BigInteger 与指定的 BigInteger 进行比较. 对于针对六个布尔比较运算符 (<, ==, >, >=, !=, <=)中的每一个运算符的各个方法,优先提供此方法. 执行这些比较的建议语句是:(x.compareTo(y) <op> 0), 其中 <op> 是