Cod sursa(job #2212804)

Utilizator Andrei_CotorAndrei Cotor Andrei_Cotor Data 14 iunie 2018 20:55:00
Problema Puteri Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.76 kb
#include<fstream>
#include<stdio.h>
#include<string.h>
using namespace std;
FILE *fi=fopen("puteri.in","r");
ofstream fo("puteri.out");
int n,i,j,k,ind,A[100005],B[100005],C[100005],Dp[130][130][130],a,b,c,g,nrd,x,val,Mod[130];
long long rez;
char S[100005];
int l;

void nextS()
{
    ind=0;
    fread(S,1,100000,fi);
    l=strlen(S);
}

int nextInt()
{
    int r=0;
    if(ind==l)
        nextS();
    while(S[ind]<'0' || S[ind]>'9')
    {
        ind++;
        if(ind==l)
            nextS();
    }
    while(S[ind]>='0' && S[ind]<='9')
    {
        r=r*10+S[ind]-'0';
        ind++;
        if(ind==l)
            nextS();
    }
    return r;
}

int main()
{
    n=nextInt();
    for(i=1; i<=n; i++)
    {
        A[i]=nextInt();
        B[i]=nextInt();
        C[i]=nextInt();
    }
    for(i=2; i<=128; i++)
    {
        nrd=0;
        x=i;
        g=1;
        for(j=2; j*j<=x; j++)
        {
            if(x%j==0)
            {
                nrd++;
                x/=j;
                if(x%j==0)
                {
                    g=0;
                    break;
                }
            }
        }
        if(x>1)
            nrd++;
        if(g==0)
            continue;
        if(nrd%2)
            val=1;
        else
            val=-1;
        for(j=1; j<=128; j++)
            Mod[j]=j%i;
        for(j=1; j<=n; j++)
        {
            a=Mod[i-Mod[A[j]]];
            b=Mod[i-Mod[B[j]]];
            c=Mod[i-Mod[C[j]]];
            rez=rez+1LL*val*Dp[a][b][c];
            Dp[Mod[A[j]]][Mod[B[j]]][Mod[C[j]]]++;
        }
        for(j=1; j<=n; j++)
            Dp[Mod[A[j]]][Mod[B[j]]][Mod[C[j]]]=0;
    }
    fo<<rez<<"\n";
    fclose(fi);
    fo.close();
    return 0;
}