vendredi 18 décembre 2020

Last digit of sum

In a problem i need to find last digit of a sum's result:: S=1^4 + 2^4 + 3^4 + ... + n^4.But , i don't know why i take only 40% at this problem.

#include <iostream>
#include <cmath>
using namespace std;

int main()
{

    int n;
    cin >> n;
    long long pow = 1, result=1;
   
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j < 5; j++)
        {
            result = 1LL * pow * i;
        }
    }
    int cifra = result % 10;
    cout << cifra;




    return 0;

}

Ex Input 4 and output will be also 4 , because S=1+16+81+256=354, and last digit is 4

Aucun commentaire:

Enregistrer un commentaire