H - the Sum of Cube(水题)
InputThe first line of the input is T(1 <= T <= 1000), which stands for the number of test cases you need to solve.
Each case of input is a pair of integer A,B(0 < A <= B <= 10000),representing the range[A,B].OutputFor each test case, print a line “Case #t: ”(without quotes, t means the index of the test case) at the beginning. Then output the answer – sum the cube of all the integers in the range.Sample Input
2
1 3
2 5
Sample Output
Case #1: 36
Case #2: 224
首先要明白这一题的题意,就是求一个范围内的所有整数数的立方和
注意:数据范围要用 long long
求立方和可以用pow函数——>pow(j, 3)
感觉第二个数据错了…………
AC代码
#include<stdio.h> int solve(int x)
{
return x*x*x;
} int main()
{
int t;
int num = ;
scanf("%d", &t);
while(t--)
{
int a, b;
long long sum = ; scanf("%d %d", &a, &b);
for(int i = a; i <= b; i++)
{
sum += solve(i);
}
num++;
printf("Case #%d: %lld\n", num, sum);
}
return ;
}
H - the Sum of Cube(水题)的更多相关文章
- HDU5053the Sum of Cube(水题)
HDU5053the Sum of Cube(水题) 题目链接 题目大意:给你L到N的范围,要求你求这个范围内的全部整数的立方和. 解题思路:注意不要用int的数相乘赋值给longlong的数,会溢出 ...
- Xtreme8.0 - Sum it up 水题
Sum it up 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/sum-it-up Descr ...
- cdoj 80 Cube 水题
Cube Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/80 Descrip ...
- codeforces 577B B. Modulo Sum(水题)
题目链接: B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- poj1564 Sum It Up dfs水题
题目描述: Description Given a specified total t and a list of n integers, find all distinct sums using n ...
- hdoj--5053--the Sum of Cube(水)
the Sum of Cube Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tot ...
- SPOJ 3693 Maximum Sum(水题,记录区间第一大和第二大数)
#include <iostream> #include <stdio.h> #include <algorithm> #define lson rt<< ...
- HDU 4593 H - Robot 水题
H - RobotTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...
- HDU 4788 Hard Disk Drive (2013成都H,水题)
Hard Disk Drive Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
随机推荐
- 蓝桥杯 基础练习 BASIC-24 龟兔赛跑预测
基础练习 龟兔赛跑预测 时间限制:1.0s 内存限制:512.0MB 问题描述 话说这个世界上有各种各样的兔子和乌龟,但是研究发现,所有的兔子和乌龟都有一个共同的特点——喜欢赛跑.于是世界上各 ...
- java继承 子类重写父类方法
package com.addd; //多态 public class Sld { private String name = "zhangsan"; public Sld() { ...
- 9-EasyNetQ之基于主题的路由
RabbitMQ有一个很酷的功能,基于主题的路由,这个功能允许订阅者基于多个条件去过滤消息.一个主题是由点号分隔的单词列表,随消息一同发布.例如:"stock.usd.nyse" ...
- findall 、 search的使用
- 使用ServerSocket建立聊天服务器(一)
-------------siwuxie095 工程名:TestMyServerSocket 包名:com.siwuxie095.socket ...
- windows 7 系统装机优化
A:系统设置 1.控制面板\系统和安全\Windows Update\更改设置 把系统升级以及提示关闭 控制面板\系统和安全\Windows 防火墙\自定义设置 把专用网络和公共网络的防火 ...
- ubuntu16.04 安装caffe2
1.使用conda创建环境 conda create --name caffe2env python=3.6 ---------------------------------success----- ...
- C++标准库vector以及迭代器
今天看C++的书,出现了一个新的概念,容器vector以及容器迭代器. vector是同一种对象的集合,每个对象都有一个对应的整数索引值.和string对象一样,标准库将负责管理与存储元素相关的类存. ...
- oracle数据库输入conn / as sysdba 出现ORA-01031: insufficient privileges + 忘记sys密码如何改密码
今天忘记了oracle数据库sys用户的密码,想着直接改密码输入conn / as sysdba 出现了ORA-01031: insufficient privileges(权限不足)的错误,到处搜教 ...
- c++ 切勿重新定义继承来的带缺省参数的函数
切勿重新定义继承来的带缺省参数的函数.我们知道,继承来的函数是virtual 的,至于原因在上一节中已经说明了,即“切勿重新定义父类non-virtual函数”.所以确切的描述应该是“切勿重新定义继承 ...