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

It's very simple problem, but you don't need to sort the elements :-)
Posted by Veselin Kolev 11 Sep 2004 21:51
#include <iostream>

using namespace std;

short n;
unsigned long a[1000];

void Input()
     {cin>>n;
      for (short i=0; i<n; i++)
          cin>>a[i];
     }

unsigned long gcd(unsigned long a, unsigned long b)
         {unsigned long x;
          while (b>0)
                {x=b;
                 b=a%b;
                 a=x;
                }
          return a;
         }

void Solve()
     {for (short i=1; i<n; i++)
          a[i]=gcd(a[i-1],a[i]);
     }

void Output()
     {cout<<a[n-1]<<"\n";
     }

int main()
    {Input();
     Solve();
     Output();
     return 0;
    }

Edited by author 11.09.2004 21:52
No subject
Posted by [OSTU] Alex Svetkin 22 Sep 2004 18:01
You even may keep in memory only two elements.