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)
  • 相关阅读:
    异常
    gateway 网关
    Hystrix 图形化界面
    Hystrix 服务限流
    linux-CenOS修复内核或修改内核系统启动顺序
    Linux-CentOS不能yum update/upgrade.除非是初始环境
    Linux-CentOS配置网卡
    安装SQLSERVER2008提示错误SQL100MSI
    金蝶采购标志
    Pycharm社区版安装外部库文件
  • 原文地址:https://www.cnblogs.com/h-hkai/p/8528667.html
Copyright © 2011-2022 走看看