An Easy Problem
来源:互联网 发布:c语言1到100以内的质数 编辑:程序博客网 时间:2024/06/13 04:36
- 输入
- The first line contains an integer T, indicates the number of test case.
The next T lines, each line contains two integers L and R(1≤L,R≤10^5). - 输出
- Print an integer represents the sum.
- 样例输入
21 22 4
样例输出
5
29
//代码如下
#include<iostream>#include<stdio.h>using namespace std;int main(){int n;double a,b,i,sum;while(cin>>n){while(n--){cin>>a>>b;sum=0;if(a>b) swap(a,b);for(i=a;i<=b;i++)sum+=i*i;printf("%.lf\n",sum);//此处不能用cout,因为数较大,不能完整的输出}}return 0;}
//参考别人的代码(用的是long long型的)#include <cstdio>#include <algorithm>using namespace std;typedef long long LL;inline LL get_sum(LL x) { return x * (x + 1) * (2 * x + 1) / 6;//从1到x的平方的和的公式}int main() { int T; LL L, R; scanf("%d", &T); while(T--) { scanf("%lld%lld",&L, &R); if(L > R) swap(L, R); printf("%lld\n", get_sum(R) - get_sum(L - 1)); } return 0;}
0 0
- An Easy Problem
- 2055 An easy problem
- An Easy Problem!
- An Easy Problem!
- poj2826 An Easy Problem?!
- HDOJ2055 An easy problem
- An Easy Problem
- hdu-An Easy Problem
- hdu2601 An easy problem
- An Easy Problem
- hdu-An Easy Problem
- HDU_2055 An easy problem
- HDU_2123 An easy problem
- B - An easy problem
- B - An easy problem
- An easy problem
- An easy problem 2132
- An easy problem 2123
- Android报java.lang.IllegalAccessException: access to class not allowed错误
- stm32的低功耗模式和RTC闹钟唤醒
- 贪吃蛇总结之二
- Android视图绘制流程完全解析,带你一步步深入了解View(二)
- 机器学习实战之决策树(1)---ID3算法与信息熵,基尼不纯度
- An Easy Problem
- 博客小记
- Linux内核线程
- 子网掩码详解
- kbengine系列教程一
- java中list跟set的异同点
- 浅谈 linux 多线程编程和 windows 多线程编程的异同
- linux 别名
- Linux 任务调度命令