ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1053. Pinocchio

To admins
Posted by SigmaPhiZeta 9 Nov 2015 19:09
заходит решение
берем пары соседних чисел и выводим минимум из их нодов(

#include <iostream>
#include <vector>

using namespace std;

int gcd(int a, int b)
{
    if(a == b)
        return a;
    while( a != 0 && b !=0)
        if(a > b)
            a%=b;
        else b%=a;
    return a+b;
}
int main()
{
    int N;
    cin >> N;
    int array[1000];
    for(int i = 0; i < N; i++)
        cin >> array[i];
    if(N == 1) cout << array[0];
    else{
    vector <int> mins;
    for(int i = 0; i < N-1; i++)
        mins.push_back(gcd(array[i], array[i+1]));
    int min = mins[0];
    for(int i = 0 ;i < mins.size(); i++)
        if(min > mins[i])
            min = mins[i];
    cout << min;
    }
    return 0;
}
это вроде не камильфо!
Test was added (-)
Posted by Sandro (USU) 10 Nov 2015 21:18