Cod sursa(job #1532796)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 21 noiembrie 2015 16:36:28
Problema Indep Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <fstream>
#include <iostream>
#include <array>
#include <algorithm>
using namespace std;

constexpr int gcd(const int a, const int b){
	return b == 0 ? a : gcd(b, a%b); }

int main(){
	ifstream f("indep.in");
	ofstream g("indep.out");
	array<array<int, 1001>, 1001> gcd_table;

	for(int i = 0; i <= 1000; ++i){
		gcd_table[i][0] = gcd_table[0][i] = i; }
	for(int i = 1; i <= 1000; ++i){
		for(int j = 1; j <= i; ++j){
			gcd_table[i][j] = gcd_table[j][i] = gcd_table[i-j][j]; } }

	int n;
	f >> n;
	array<array<uint64_t, 1001>, 2> d = {};

	for(int i = 0, x; i < n; ++i){
		f >> x;
		d[i%2] = d[(i+1)%2];
		for(int j = 1; j <= 1000; ++j){
			d[i%2][gcd_table[j][x]] += d[(i+1)%2][j]; }
		++d[i%2][x]; }
	g << d[(n+1)%2][1] << '\n';
	return 0; }