Cod sursa(job #541655)

Utilizator gorgovanAurelian Namascu gorgovan Data 25 februarie 2011 13:01:36
Problema Light2 Scor 10
Compilator cpp Status done
Runda Romanian Master in Mathematics and Sciences 2011, Ziua 1 Marime 0.77 kb
using namespace std;

#include<iostream>
#include<fstream>

#define ll long long
ofstream fout("light2.out");
int K,N,d[30];
void solve()
{
    ll sol=0;
    int i,j;
    for(i=1;i<(1<<K);i++)
    {
        ll nr=0,prod=1;
        cout<<i<<" :";
        for(j=0;j<K;j++)
        if((1<<j)&i)
        {
            prod=prod*d[j+1];
            nr++;
            cout<<j+1<<" ";
        }
        //cout<<"\n";
        if(nr%2) nr=1;
        else
        nr=-2;
        sol=sol+nr*N/prod;
    }
    fout<<sol<<"\n";
}

void cit()
{
    ifstream fin("light2.in");

    fin>>N;
    fin>>K;
    int i;
    for(i=1;i<=K;i++)
      fin>>d[i];
    fin.close();
}

int main()
{


    cit();
    solve();

    fout.close();
    return 0;
}