Project Euler 006 Sum Square Difference

Source: Internet
Author: User

Test Instructions: ∑100i=1i2− (∑100i=1i) 2 \sum_{i = 1} ^ {100}i^2-(\sum _ {i = 1} ^ {100}i) ^2
Analysis: There are still two ways to consider.
1. Violence seeks out two values.
2. The previous one equals n (n+1) (2n+1) 6 \frac{n (n + 1) (2n + 1)}{6}, and the latter Equals (n (n+1) 2) 2 \left (\frac{n (n + 1)}{2}\right) ^2.

#include <bits/stdc++.h> #define LL Long long #define PII std::p air<int,int> #define MP Std::make_pair #defi Ne fi first #define SE second #define SZ (x) (int) (x). Size () #define PB push_back template<class t>inline void chkm Ax (t &x, const T &y) {if (x < y) x = y;} template<class t>inline void Chkmin (t &x, const T &y) {if

(x > Y) x = y;}
    Template<class t> inline void read (T &x) {char C;int f = 1;x = 0;
    while ((C=getchar () < ' 0 ' | | c > ' 9 ') && c! = '-');
    if (c = = '-') F = -1;else x = C ' 0 ';
    while ((C=getchar ()) >= ' 0 ' && C <= ' 9 ') x = x*10+c-' 0 ';
x *= F;
} static int outn;
static char out[(int) 2e7];
    Template<class t> inline void Write (T x) {if (x < 0) out[outn++] = '-', x =-X;
        if (x) {static int tmpn;
        static Char tmp[20];
        TMPN = 0;
        while (x) tmp[tmpn++] = x%10+ ' 0 ', x/= 10;
    while (TMPN) out[outn++] = Tmp[--tmpn]; } else Out[outn++] = ' 0 ';

} int C1 (int n) {return n * (n + 1) * (2 * n + 1)/6;}

int C2 (int n) {return n * n * (n + 1) * (n + 1)/4;}
    int main () {printf ("%d\n", C2 (+)-C1 (100));
return 0;
 }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.