zoukankan      html  css  js  c++  java
  • H

    A range is given, the begin and the end are both integers. You should sum the cube of all the integers in the range.

    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 = 0;
        scanf("%d", &t);
        while(t--)
        {
            int a, b;
            long long sum = 0;
    
            scanf("%d %d", &a, &b);
            for(int i = a; i <= b; i++)
            {
                sum += solve(i);
            }
            num++;
            printf("Case #%d: %lld
    ", num, sum);
        }
        return 0;
    }
    View Code
    永远渴望,大智若愚(stay hungry, stay foolish)
  • 相关阅读:
    解释器
    桥接
    组合
    hbase读性能优化
    Hbase为什么写比读快
    http和https区别
    R apply() 函数和 tapply() 函数
    R 语言 decostand() 函数
    R多行交叉作图
    k-mean 拐点
  • 原文地址:https://www.cnblogs.com/h-hkai/p/8528667.html
Copyright © 2011-2022 走看看