1
+ {
2
+ "nbformat" : 4 ,
3
+ "nbformat_minor" : 0 ,
4
+ "metadata" : {
5
+ "colab" : {
6
+ "name" : " Euler_10.ipynb" ,
7
+ "provenance" : [],
8
+ "collapsed_sections" : [],
9
+ "authorship_tag" : " ABX9TyP4CgLoNH2JVrQ9rBrP13XY" ,
10
+ "include_colab_link" : true
11
+ },
12
+ "kernelspec" : {
13
+ "name" : " python3" ,
14
+ "display_name" : " Python 3"
15
+ },
16
+ "language_info" : {
17
+ "name" : " python"
18
+ }
19
+ },
20
+ "cells" : [
21
+ {
22
+ "cell_type" : " markdown" ,
23
+ "metadata" : {
24
+ "id" : " view-in-github" ,
25
+ "colab_type" : " text"
26
+ },
27
+ "source" : [
28
+ " <a href=\" https://colab.research.google.com/github/DebjitHore/Python-Codes/blob/master/Euler_10.ipynb\" target=\" _parent\" ><img src=\" https://colab.research.google.com/assets/colab-badge.svg\" alt=\" Open In Colab\" /></a>"
29
+ ]
30
+ },
31
+ {
32
+ "cell_type" : " code" ,
33
+ "metadata" : {
34
+ "id" : " lLOdNYHJdYzm"
35
+ },
36
+ "source" : [
37
+ " #Sum of primes below two million\n " ,
38
+ " import numpy as np"
39
+ ],
40
+ "execution_count" : 53 ,
41
+ "outputs" : []
42
+ },
43
+ {
44
+ "cell_type" : " code" ,
45
+ "metadata" : {
46
+ "id" : " srAMYVLPii1S" ,
47
+ "colab" : {
48
+ "base_uri" : " https://localhost:8080/"
49
+ },
50
+ "outputId" : " e2cd45b6-0a00-40cd-e816-ee72d0a8c4ed"
51
+ },
52
+ "source" : [
53
+ " n= 4\n " ,
54
+ " count=[]\n " ,
55
+ " i=2\n " ,
56
+ " rangeNumber=int(input('Enter range till which you want to go'))\n " ,
57
+ " fullcount= np.arange(2, rangeNumber+1)\n " ,
58
+ " while n< rangeNumber+1:\n " ,
59
+ " while i<n:\n " ,
60
+ " if n%i==0:\n " ,
61
+ " count.append(n)\n " ,
62
+ " break\n " ,
63
+ " else: \n " ,
64
+ " i+=1 \n " ,
65
+ " n+=1\n " ,
66
+ " i=2 "
67
+ ],
68
+ "execution_count" : 83 ,
69
+ "outputs" : [
70
+ {
71
+ "output_type" : " stream" ,
72
+ "text" : [
73
+ " Enter range till which you want to go1000\n "
74
+ ],
75
+ "name" : " stdout"
76
+ }
77
+ ]
78
+ },
79
+ {
80
+ "cell_type" : " code" ,
81
+ "metadata" : {
82
+ "colab" : {
83
+ "base_uri" : " https://localhost:8080/"
84
+ },
85
+ "id" : " rXRT52c7jYPo" ,
86
+ "outputId" : " 915e97fd-529a-4260-89a7-ee7c260e7cc2"
87
+ },
88
+ "source" : [
89
+ " x= np.array(count)\n " ,
90
+ " print(fullcount.sum()- x.sum())\n "
91
+ ],
92
+ "execution_count" : 85 ,
93
+ "outputs" : [
94
+ {
95
+ "output_type" : " stream" ,
96
+ "text" : [
97
+ " 76127\n "
98
+ ],
99
+ "name" : " stdout"
100
+ }
101
+ ]
102
+ },
103
+ {
104
+ "cell_type" : " code" ,
105
+ "metadata" : {
106
+ "id" : " -3Ve14kFhEYa"
107
+ },
108
+ "source" : [
109
+ " #Implement Sieve of Erasthothenes"
110
+ ],
111
+ "execution_count" : 86 ,
112
+ "outputs" : []
113
+ },
114
+ {
115
+ "cell_type" : " code" ,
116
+ "metadata" : {
117
+ "colab" : {
118
+ "base_uri" : " https://localhost:8080/"
119
+ },
120
+ "id" : " d10CeJzimUhb" ,
121
+ "outputId" : " b2149f5b-4b53-4ac9-9942-41c06258baa5"
122
+ },
123
+ "source" : [
124
+ " n= int(input('Enter range upto which you want to check'))\n " ,
125
+ " sum, sieve= 0, [True]*n\n " ,
126
+ " \n " ,
127
+ " for i in range (2,n):\n " ,
128
+ " if sieve[i]:\n " ,
129
+ " sum+=i\n " ,
130
+ " for j in range(i*i, n, i):\n " ,
131
+ " sieve[j]= False\n " ,
132
+ " \n " ,
133
+ " print(sum)\n "
134
+ ],
135
+ "execution_count" : 90 ,
136
+ "outputs" : [
137
+ {
138
+ "output_type" : " stream" ,
139
+ "text" : [
140
+ " Enter range upto which you want to check2000000\n " ,
141
+ " 142913828922\n "
142
+ ],
143
+ "name" : " stdout"
144
+ }
145
+ ]
146
+ },
147
+ {
148
+ "cell_type" : " code" ,
149
+ "metadata" : {
150
+ "id" : " 5jvOZU0bnNuw"
151
+ },
152
+ "source" : [
153
+ " "
154
+ ],
155
+ "execution_count" : null ,
156
+ "outputs" : []
157
+ }
158
+ ]
159
+ }
0 commit comments