习惯性的坑点

平方和与立方和

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


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

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

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

Sample Input
 
  
1 32 5
 

Sample Output
 
  
4 2820 152

坑点: 题目中的 m 可能大于 n(容易默认m < n)
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<set>
#include<cstdlib>
#include<stdio.h>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;

int main()
	{
		LL m,n;
		while(scanf("%I64d%I64d",&m,&n) !=EOF){
			LL s1 = 0,s2 = 0;
			if(m > n){
				int t = m;m = n; n = t;
			}
			for(LL i = m; i <= n; ++i){
				if(i%2 == 0){
					s1 += i*i;
				}
				else{
					s2 += i*i*i;
				}
			}
			printf("%I64d %I64d\n",s1,s2);
		} 

		return 0;
	}

 
 



猜你喜欢

转载自blog.csdn.net/tianweidadada/article/details/80491052
今日推荐