Cod sursa(job #1446396)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 1 iunie 2015 18:55:04
Problema Indep Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <fstream>
#include <array>
#include <algorithm>
using namespace std;

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

void add_num(const int x, array<int, 1001>& info){
	static array<int, 1001> tmp;
	tmp = info;
	for(int i = 1; i <= 1000; ++i){
		info[gcd(i, x)] += tmp[i]; }
	++info[x]; }

int main(){
	ifstream f("indep.in");
	ofstream g("indep.out");
	int n;
	f >> n;
	array<int, 1001> info = {0};
	for(int i = 0, x; i < n; ++i){
		f >> x;
		add_num(x, info); }
	g << info[1] << '\n';
	return 0; }