Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "4\n",
- "5 13 8 1000000000\n",
- "1\n",
- "1\n",
- "Wall time: 3.15 s\n"
- ]
- }
- ],
- "source": [
- "%%time\n",
- "import math\n",
- "\n",
- "N = int(input())\n",
- "Ai = list(map(int, input().split()))\n",
- "if Ai == [Ai[0]] * len(Ai):\n",
- " print(Ai[0])\n",
- " quit()\n",
- " \n",
- " \n",
- "i = 1\n",
- "min = 1000000000\n",
- "a = Ai[0]\n",
- "\n",
- "for a2 in Ai[1:]:\n",
- " a_gcd = math.gcd(a, a2)\n",
- " if min > a_gcd:\n",
- " min = a_gcd\n",
- " if min <= 2:\n",
- " print(min)\n",
- " quit()\n",
- " \n",
- "print(min)\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "4\n",
- "5 13 8 1000000000\n",
- "1\n",
- "Wall time: 3.86 s\n"
- ]
- }
- ],
- "source": [
- "%%time\n",
- "import math\n",
- "from functools import reduce\n",
- "\n",
- "N = int(input())\n",
- "Ai = list(map(int, input().split()))\n",
- "if Ai == [Ai[0]] * len(Ai):\n",
- " print(Ai[0])\n",
- " quit()\n",
- "\n",
- "print(reduce(math.gcd, Ai))\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": []
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.6.3"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement