Cod sursa(job #1344361)

Utilizator MaarcellKurt Godel Maarcell Data 16 februarie 2015 17:50:52
Problema Light2 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <iostream>
#include <fstream>
#define LL long long int
using namespace std;

LL N,d[30],sum; int K,P;

inline LL gcd(LL a, LL b){
    if (!b) return a;
    return gcd(b,a%b);
}

void comb(int cnt, int ind, LL aux){
    if (aux>N || aux<0) return;

    if (ind>K){
        if (cnt==0) return;
        if (cnt%2) sum+=(1<<(cnt-1))*(N/aux);
        else sum-=(1<<(cnt-1))*(N/aux);
        return;
    }

    comb(cnt,ind+1,aux);
    comb(cnt+1,ind+1,aux*d[ind]/gcd(aux,d[ind]));
}

int main(){
    ifstream fin("light2.in");
    ofstream fout("light2.out");
    fin >> N >> K;

    LL i;
    for (i=1; i<=K; i++) fin >> d[i];
    comb(0,1,1);

    fout << sum;
    return 0;
}