Pagini recente » infoarena_runda_3 | Cod sursa (job #2902633) | Cod sursa (job #552264) | Cod sursa (job #2081433) | Cod sursa (job #341312)
Cod sursa(job #341312)
// another fine solution by misof
// #includes {{{
#include <algorithm>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <cmath>
#include <complex>
using namespace std;
// }}}
/////////////////// PRE-WRITTEN CODE FOLLOWS, LOOK DOWN FOR THE SOLUTION ////////////////////////////////
// pre-written code {{{
// }}}
/////////////////// CODE WRITTEN DURING THE COMPETITION FOLLOWS ////////////////////////////////
#include <fstream>
// definicia triedy bigInt
class bigInt {
public:
// premenna s ciframi
vector<int> digits;
// konstruktory: prazdny, copy, z celeho cisla, zo stringu
bigInt();
bigInt(const bigInt &);
bigInt(int);
bigInt(string);
// priradenie
void operator =(const bigInt &);
void operator =(int);
void operator =(string);
void operator +=(const bigInt &);
void operator +=(int);
// modifikujuce fcie
void utras();
void add(int);
void add(const bigInt &);
// vypis
string toString();
};
// implementacie konstruktorov
bigInt::bigInt() { digits.clear(); digits.push_back(0); }
bigInt::bigInt(const bigInt &A) { digits=A.digits; }
bigInt::bigInt(int x) { digits.clear(); while(x) { digits.push_back( x%10 ); x /= 10; } }
bigInt::bigInt(string x) { digits.clear(); digits.resize(x.size()); for (unsigned int i=0; i<x.size(); i++) digits[x.size()-1-i] = x[i]-'0'; utras(); }
// implementacia priradenia
void bigInt::operator =(const bigInt &A) { digits=A.digits; }
void bigInt::operator =(int x) { digits.clear(); while(x) { digits.push_back( x%10 ); x /= 10; } }
void bigInt::operator =(string x) { digits.clear(); digits.resize(x.size()); for (unsigned int i=0; i<x.size(); i++) digits[x.size()-1-i] = x[i]-'0'; utras(); }
// utras: upravi do normalneho tvaru
void bigInt::utras() {
int zv = 0;
for (unsigned int i=0; i<digits.size(); i++) { digits[i]+=zv; zv=digits[i] / 10; digits[i] %= 10; }
while (zv) { digits.push_back( zv%10 ); zv /= 10; }
while ((digits.size()>1) && (*(digits.end()-1) == 0)) digits.pop_back();
}
// add: pripocita cislo
void bigInt::add(const bigInt &B) {
digits.resize( max( digits.size(), B.digits.size() ), 0 );
for (unsigned int i=0; i<B.digits.size(); i++) digits[i]+=B.digits[i];
utras();
}
void bigInt::add(int x) { bigInt _x(x); add(_x); }
// toString: vrati string s ciframi v danej baze
string bigInt::toString() {
string res;
for (int i=int(digits.size())-1; i>=0; i--) res += digits[i]+'0';
if (res=="") res="0";
return res;
}
// binarne operatory: +
bigInt operator + (const bigInt &A, const bigInt &B) { bigInt C(A); C.add(B); return C; }
bigInt operator + (const bigInt &A, int B) { bigInt _B(B); bigInt C(A); C.add(_B); return C; }
bigInt operator + (int A, const bigInt &B) { bigInt _A(A); bigInt C(_A); C.add(B); return C; }
void bigInt::operator +=(const bigInt &A) { this->add(A); }
void bigInt::operator +=(int A) { this->add(A); }
ostream& operator << (ostream& s, const bigInt &A) { bigInt _A(A); return (s << _A.toString()); }
istream& operator >> (istream& s, bigInt &A) { string S; s >> S; A = S; return s; }
int main() {
ifstream fin("indep.in");
vector<bigInt> oldc(1001,bigInt(0));
int N; fin >> N;
for (int n=0; n<N; ++n) {
int x; fin >> x;
vector<bigInt> newc = oldc;
for (int i=1; i<=1000; ++i) newc[ __gcd(i,x) ] += oldc[i];
newc[x] += 1;
oldc = newc;
}
ofstream fout("indep.out");
fout << oldc[1] << endl;
return 0;
}
// vim: fdm=marker:commentstring=\ \"\ %s:nowrap:autoread