A. Complete square number (the sum of the squares of the first n items) High-precision addition, subtraction, multiplication and division example problem

A. Complete Square Number
Description
In the St. Comet Lan Women's College, these seven incredible stories are circulated.
One of them is called: The Werewolf of the Bell Tower.
Legend has it that the werewolves of the clock tower will appear at a specific time at night, and in order to figure out when the werewolves will appear next time, you decide to ask a little H classmate who is very good at math. However, classmate Xiao H is dating her boyfriend, so impatient she threw you such a problem and said to you: solve this problem and then come to me.
In order to know the secrets of the werewolves in the clock tower, you must learn to solve this problem as soon as possible. Of course, you are very happy after hearing this question, because this question is too simple for you. The question is: find the value of 12+22+32+……+n2.

Input
one line, an integer n.


One line of Output , an integer, represents this value

Samples
Input Copy
3
Output
14
Hint
[Explanation]
1^2+ 2^ 2+3^ 2=1+4+9=14.

【data range】

For 30% of the data, 3≤n≤1000000.
For 100% data, 3≤n≤10^1000.
The input data ensures that n does not contain leading zeros.

[Remarks] 1^2+ 2^2 + 3^2+……+ n^ 2=n*(n+1)*(2n+1)/6.
,,,,,,,,,,,,,,,,,,,,,,,,,,

Hard work and scattered learning high precision, although I only learned a little bit

I'm drunk too, don't know how to say it, there are a lot of high precision not 1

This question is high precision. If you can’t, you still have to look at high precision and then look at this question.

(My blog seems to have a high-precision eh Hey, how to say that I think this blog is written by title only)
I can not play this second wave

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn =1e6+199 ;
char shu1[maxn];
int qo1[maxn];
int qo2[maxn];
int qo3[maxn];
int jg[maxn]={
    
    0};
int jg1[maxn]={
    
    0};
int jg2[maxn]={
    
    0};
void jia(int a[])
{
    
    
    a[1]+=1;
    int i=1;
   while(a[i]==10)
   {
    
    
       a[i]=0;
       a[i+1]++;

       a[0]+=(i==a[0]);
       i++;
   }
}
void gcheng(int a[],int b[])
{
    
    
    jg[0]=a[0]+b[0];
    for(int i=1;i<=a[0];i++)
    {
    
    
        for(int j=1;j<=b[0];j++)
        {
    
    
            jg[i+j-1]+=a[i]*b[j];
        }
    }

    for(int i=1;i<=jg[0];i++)
    {
    
    
        if(jg[i]>=10)
        {
    
    
            jg[i+1]+=jg[i]/10;
            jg[i]%=10;

            jg[0]+=(i==jg[0]);
        }

    }

     while(jg[0]>1&&jg[jg[0]]==0)
    {
    
    
        jg[0]--;
    }

}
void gcheng1(int a[],int b[])
{
    
    
     jg1[0]=a[0]+b[0];
    for(int i=1;i<=a[0];i++)
    {
    
    
        for(int j=1;j<=b[0];j++)
        {
    
    
            jg1[i+j-1]+=a[i]*b[j];
        }
    }

    for(int i=1;i<=jg1[0];i++)
    {
    
    
        if(jg1[i]>=10)
        {
    
    
            jg1[i+1]+=jg1[i]/10;
            jg1[i]%=10;
            jg1[0]+=(i==jg1[0]);
        }

    }
     while(jg1[0]>1&&jg1[jg1[0]]==0)
    {
    
    
        jg1[0]--;
    }
}
void dcheng(int a[])
{
    
    
    for(int i=1;i<=a[0];i++)
    {
    
    
        a[i]*=2;
    }

   for(int i=1;i<=a[0];i++)
    {
    
    
        if(a[i]>=10)
        {
    
    

        a[i+1]+=a[i]/10;
        a[i]%=10;
        a[0]+=(i==a[0]);
        }
    }
}
void chu(int a[],int n)
{
    
    
    int x=0;
     for(int i=a[0];i>=1;i--)
    {
    
    
        jg2[i]=(x*10+a[i])/n;
        x=(x*10+a[i])%n;
    }
    jg2[0]=a[0];
    while(jg2[jg2[0]]==0&&jg2[0]>1)
        jg2[0]--;

}
void pl(int a[])
{
    
    
    for(int i=a[0];i>=1;i--)
        cout<<a[i];
}
int main()
{
    
    
	scanf("%s",shu1);
	int len1=strlen(shu1);
	for(int i=0;i<len1;i++)
    {
    
    
        qo1[len1-i]=shu1[i]-'0';
        qo2[len1-i]=shu1[i]-'0';
        qo3[len1-i]=shu1[i]-'0';
    }
    qo1[0]=qo2[0]=qo3[0]=len1;
    jia(qo2);
    dcheng(qo3);
    jia(qo3);
    gcheng(qo1,qo2);
    gcheng1(jg,qo3);
    chu(jg1,6);
    pl(jg2);
    return 0;
}

Guess you like

Origin blog.csdn.net/qq_52172364/article/details/113202836