Cod sursa(job #1576340)

Utilizator magda23245Chiperescu Magda magda23245 Data 22 ianuarie 2016 12:11:33
Problema Algoritmul lui Euclid Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.55 kb
#include <fstream>

using namespace std;

int main()
{
    int S,N,P;
    ifstream fin ("suma.in");
    ofstream fout ("suma.out");
    fin>>N>>P;
    if((N-1)%3==0)
    {
        S=(N-1)/3;
        S=(1LL *S*N)%P;
        S=(1LL*S*(N+1))%P;
    }
    else if (N%3==0)
    {
        S=N/3;
        S=(1LL*S*(N-1))%P;
        S=(1LL*S*(N+1))%P;
    }
    else if((N+1)%3==0)
    {
        S=(N+1)/3;
        S=(1LL*S*N)%P;
        S=(1LL*S*(N-1))%P;
    }

    fout<<S;

    fin.close ();
    fout.close ();

    return 0;
}