Cod sursa(job #18524)

Utilizator flo_demonBunau Florin flo_demon Data 18 februarie 2007 12:32:09
Problema Reguli Scor 0
Compilator cpp Status done
Runda preONI 2007, Runda 2, Clasele 11-12 Marime 1.2 kb
#include <stdio.h>
#include <iostream>

using namespace std;

#define MAX 500005

long long a[MAX], v[MAX];
int n, rez;

int main()
{
    FILE *fin = fopen("reguli.in", "r");
    fscanf(fin, "%lld", &n);
    for (int i = 1; i <= n; ++i)
        fscanf(fin, "%lld", &a[i]);
    fclose(fin);
    
    for (int i = 2; i <= n; ++i)
        v[i-1] = a[i] - a[i-1];
        
    int pos;
    bool bad, end_cycle;
    for (int j = 1; j <= n-1; ++j)
    {
        pos = 1;
        bad = false;
        while (1)
        {
            end_cycle = false;
            for (int i = 1; i <= n-1; ++i)
            {
                if (pos*j+i >= n) { end_cycle = true; break; }
                if (v[i] != v[pos*j + i])
                    bad = true;
            }
            if (!bad) pos++;
            else
                break;
            if (end_cycle) break;
        }
        if (end_cycle == true && bad == false)
        {
            rez = j;
            break;
        }
    }
    
    FILE *fout = fopen("reguli.out", "w");
    fprintf(fout, "%lld\n", rez);
    for (int i = 1; i <= rez; ++i)
        fprintf(fout, "%lld\n", v[i]);
    fclose(fout);
    
    return 0;
}