Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {},
  7. "outputs": [
  8. {
  9. "name": "stdout",
  10. "output_type": "stream",
  11. "text": [
  12. "4\n",
  13. "5 13 8 1000000000\n",
  14. "1\n",
  15. "1\n",
  16. "Wall time: 3.15 s\n"
  17. ]
  18. }
  19. ],
  20. "source": [
  21. "%%time\n",
  22. "import math\n",
  23. "\n",
  24. "N = int(input())\n",
  25. "Ai = list(map(int, input().split()))\n",
  26. "if Ai == [Ai[0]] * len(Ai):\n",
  27. " print(Ai[0])\n",
  28. " quit()\n",
  29. " \n",
  30. " \n",
  31. "i = 1\n",
  32. "min = 1000000000\n",
  33. "a = Ai[0]\n",
  34. "\n",
  35. "for a2 in Ai[1:]:\n",
  36. " a_gcd = math.gcd(a, a2)\n",
  37. " if min > a_gcd:\n",
  38. " min = a_gcd\n",
  39. " if min <= 2:\n",
  40. " print(min)\n",
  41. " quit()\n",
  42. " \n",
  43. "print(min)\n"
  44. ]
  45. },
  46. {
  47. "cell_type": "code",
  48. "execution_count": 3,
  49. "metadata": {},
  50. "outputs": [
  51. {
  52. "name": "stdout",
  53. "output_type": "stream",
  54. "text": [
  55. "4\n",
  56. "5 13 8 1000000000\n",
  57. "1\n",
  58. "Wall time: 3.86 s\n"
  59. ]
  60. }
  61. ],
  62. "source": [
  63. "%%time\n",
  64. "import math\n",
  65. "from functools import reduce\n",
  66. "\n",
  67. "N = int(input())\n",
  68. "Ai = list(map(int, input().split()))\n",
  69. "if Ai == [Ai[0]] * len(Ai):\n",
  70. " print(Ai[0])\n",
  71. " quit()\n",
  72. "\n",
  73. "print(reduce(math.gcd, Ai))\n"
  74. ]
  75. },
  76. {
  77. "cell_type": "code",
  78. "execution_count": null,
  79. "metadata": {
  80. "collapsed": true
  81. },
  82. "outputs": [],
  83. "source": []
  84. },
  85. {
  86. "cell_type": "code",
  87. "execution_count": null,
  88. "metadata": {
  89. "collapsed": true
  90. },
  91. "outputs": [],
  92. "source": []
  93. }
  94. ],
  95. "metadata": {
  96. "kernelspec": {
  97. "display_name": "Python 3",
  98. "language": "python",
  99. "name": "python3"
  100. },
  101. "language_info": {
  102. "codemirror_mode": {
  103. "name": "ipython",
  104. "version": 3
  105. },
  106. "file_extension": ".py",
  107. "mimetype": "text/x-python",
  108. "name": "python",
  109. "nbconvert_exporter": "python",
  110. "pygments_lexer": "ipython3",
  111. "version": "3.6.3"
  112. }
  113. },
  114. "nbformat": 4,
  115. "nbformat_minor": 2
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement