Problem 6

本文介绍了一个简单的C++程序,用于计算前100个自然数的平方和与这些数和的平方之间的差值,并提供了解决方案的源代码。

Problem

The sum of the squares of the first ten natural numbers is,

12 + 22 + ... + 102 = 385

The square of the sum of the first ten natural numbers is,

(1 + 2 + ... + 10)2 = 552 = 3025

Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.

Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.


Code

#include <iostream>
using namespace std;

int main()
{
    long long a = 0;
    long long b = 0;
    for (long long i = 1; i <= 100; i++)
    {
        a += i*i;
        b += i;
    }
    cout << b*b - a << endl;
}



Installing dependencies from lock file (including require-dev) Verifying lock file contents can be installed on current platform. Your lock file does not contain a compatible set of packages. Please run composer update. Problem 1 - Root composer.json requires PHP extension ext-redis * but it is missing from your system. Install or enable PHP's redis extension. Problem 2 - endroid/qrcode is locked to version 3.6.0 and an update of this package was not requested. - endroid/qrcode 3.6.0 requires ext-gd * -> it is missing from your system. Install or enable PHP's gd extension. Problem 3 - fastknife/ajcaptcha is locked to version v1.1.5 and an update of this package was not requested. - fastknife/ajcaptcha v1.1.5 requires ext-gd * -> it is missing from your system. Install or enable PHP's gd extension. Problem 4 - intervention/image is locked to version 2.7.2 and an update of this package was not requested. - intervention/image 2.7.2 requires ext-fileinfo * -> it is missing from your system. Install or enable PHP's fileinfo extension. Problem 5 - league/flysystem is locked to version 1.0.69 and an update of this package was not requested. - league/flysystem 1.0.69 requires ext-fileinfo * -> it is missing from your system. Install or enable PHP's fileinfo extension. Problem 6 - mpdf/mpdf is locked to version v8.0.6 and an update of this package was not requested. - mpdf/mpdf v8.0.6 requires ext-gd * -> it is missing from your system. Install or enable PHP's gd extension. Problem 7 - overtrue/wechat is locked to version 4.2.20 and an update of this package was not requested. - overtrue/wechat 4.2.20 requires ext-fileinfo * -> it is missing from your system. Install or enable PHP's fileinfo extension. Problem 8 - setasign/fpdf is locked to version 1.8.4 and an update of this package was not requested. - setasign/fpdf 1.8.4 requires ext-gd * -> it is missing from your system. Install or enable PHP's gd extension. Problem 9 - simplesoftwareio/simple-qrcode is locked to version 4.2.0 and an update of this package was not requested. - simplesoftwareio/simple-qrcode 4.2.0 requires ext-gd * -> it is missing from your system. Install or enable PHP's gd extension. Problem 10 - symfony/translation is locked to version v6.0.0 and an update of this package was not requested. - symfony/translation v6.0.0 requires php >=8.0.2 -> your php version (7.4.0) does not satisfy that requirement. Problem 11 - symfony/translation-contracts is locked to version v3.0.0 and an update of this package was not requested. - symfony/translation-contracts v3.0.0 requires php >=8.0.2 -> your php version (7.4.0) does not satisfy that requirement. Problem 12 - cache/filesystem-adapter is locked to version 1.0.0 and an update of this package was not requested. - cache/filesystem-adapter 1.0.0 requires league/flysystem ^1.0 -> satisfiable by league/flysystem[1.0.69]. - league/flysystem 1.0.69 requires ext-fileinfo * -> it is missing from your system. Install or enable PHP's fileinfo extension. To enable extensions, verify that they are enabled in your .ini files: - E:\software\php\php.ini You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode. Alternatively, you can run Composer with `--ignore-platform-req=ext-redis --ignore-platform-req=ext-gd --ignore-platform-req=ext-fileinfo` to temporarily ignore these required extensions.
最新发布
08-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值