Cod sursa(job #1472798)

Utilizator cojocarugabiReality cojocarugabi Data 17 august 2015 19:40:19
Problema Indep Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 4.08 kb
# include <bits/stdc++.h>
using namespace std;
ifstream fi("indep.in");
ofstream fo("indep.out");
# define db double
# define ll unsigned long long
# define pi 3.14159265359
# define rad(x) (x * pi / 180)
const int p_1[] = {1,-1};
const int mod1 = 1e9 + 7;
const int mod2 = 666013;
const int mod3 = 997;
template < class T > inline T sqr(T x) {return x*x;}
template < class T > inline T min(T a,T b,T c) {return min(a,min(b,c));}
template < class T > inline T min(T a,T b,T c,T d) {return min(min(a,b),min(b,c));}
template < class T > inline T max(T a,T b,T c) {return max(a,max(b,c));}
template < class T > inline T max(T a,T b,T c,T d) {return max(max(a,b),max(b,c));}
template < class T > inline T det(T a,T b,T c,T d) {return a * c - b * d;}
template < class T > inline T det(T s[3][3])
{
    return - s[0][0] * det(s[1][1],s[1][2],s[2][1],s[2][2]) + s[0][1] * det(s[1][0],s[1][2],s[2][0],s[2][2]) - s[0][2] * det(s[1][0],s[1][1],s[2][0],s[2][1]);
}
template < class T1 , class T2 , class T3 > inline T3 pow(T1 a,T2 b,T3 mod) {T3 ans = 1;while (b){if (b&1) ans = (1LL * ans * a) % mod;a = (1LL * a * a) % mod;b >>= 1;}return ans;}
template < class T > T phi(T n){T cnt = n,p = n,ans = n;for (T i = 2;i*i <= p;++i)if (!(cnt%i)){ans /= i;ans *= (i-1);while (!(cnt%i)) cnt /= i;}if (cnt > 1) ans /= cnt,ans *= (cnt - 1);return ans;}
template < class T > T f(T a,T b) {return a < b ? 0 : a / b + f(a / b);}
template < class T > T gcd(T a,T b) {return __gcd(a,b);}
class Reader {
  public:
    Reader(const string& filename):
            m_stream(filename),
            m_pos(kBufferSize - 1),
            m_buffer(new char[kBufferSize]) {
        next();
    }

    Reader& operator>>(int& value) {
        value = 0;
        while (current() < '0' || current() > '9')
            next();
        while (current() >= '0' && current() <= '9') {
            value = value * 10 + current() - '0';
            next();
        }
        return *this;
    }

  private:
    const int kBufferSize = 32768;

    char current() {
        return m_buffer[m_pos];
    }

    void next() {
        if (!(++m_pos != kBufferSize)) {
            m_stream.read(m_buffer.get(), kBufferSize);
            m_pos = 0;
        }
    }

    ifstream m_stream;
    int m_pos;
    unique_ptr<char[]> m_buffer;
};
const ll base = 1e18;
struct big
{
    vector < ll > d;
};
big t(ll b)
{
    big a;
    while (b) a.d.push_back(b%base),b /= base;
    return a;
}
void operator += (big &a,big b)
{
    ll t = 0;
    int len1 = a.d.size(),len2 = b.d.size();
     int mx = max(len1,len2);
    for (int i = 0;i < mx || t;++i)
    {
        if (i < len1) t += a.d[i];
        if (i < len2) t += b.d[i];
        if (a.d.size() == i) a.d.push_back(0);
        if (t >= base)
            a.d[i] = t - base,t = 1;
        else
            a.d[i] = t,t = 0;
    }
}
big operator + (big a,big b)
{
    a += b;
    return a;
}
void operator ++ (big &a)
{
    a += t(1);
}
big dp[2][1005];
int main(void)
{
    ifstream fi("indep.in");
    ofstream fo("indep.out");
    int n,x;
    fi>>n;
    bool ok = 0;
    while (n --)
    {
        fi>>x;
        ok = !ok;
        for (int i = 1;i <= 1e3;++i)
            dp[ok][i] = dp[!ok][i];
        for (int i = 1;i <= 1e3;++i)
            dp[ok][gcd(i,x)] += dp[!ok][i];
        ++dp[ok][x];
    }
    big ans = dp[ok][1];
    int len = ans.d.size() - 1;
    fo << ans.d[len];
    while (len)
    {
        --len;
        ll to = ans.d[len];
        if (to < 1e17) fo << 0;
        if (to < 1e16) fo << 0;
        if (to < 1e15) fo << 0;
        if (to < 1e14) fo << 0;
        if (to < 1e13) fo << 0;
        if (to < 1e12) fo << 0;
        if (to < 1e11) fo << 0;
        if (to < 1e10) fo << 0;
        if (to < 1e9) fo << 0;
        if (to < 1e8) fo << 0;
        if (to < 1e7) fo << 0;
        if (to < 1e6) fo << 0;
        if (to < 1e5) fo << 0;
        if (to < 1e4) fo << 0;
        if (to < 1e3) fo << 0;
        if (to < 1e2) fo << 0;
        if (to < 1e1) fo << 0;
        fo << to;
    }
    return fo << '\n',0;
}