Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4ed5798

Browse files
Competitive Programming
1 parent 048f9e2 commit 4ed5798

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

‎SphereOnlineJudge/Prime-Generator.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'''
2+
Peter wants to generate some prime numbers for his cryptosystem.
3+
Help him! Your task is to generate all prime numbers between two given numbers!
4+
5+
Input
6+
The input begins with the number t of test cases in a single line (t<=10).
7+
In each of the next t lines there are two numbers m and n (1 <= m <= n <= 1000000000, n-m<=100000) separated by a space.
8+
9+
Output
10+
For every test case print all prime numbers p such that m <= p <= n, one number per line, test cases separated by an empty line.
11+
12+
Example:
13+
Input:
14+
2
15+
1 10
16+
3 5
17+
Output:
18+
2
19+
3
20+
5
21+
7
22+
23+
3
24+
5
25+
26+
Warning: large Input/Output data, be careful with certain languages (though most should be OK if the algorithm is well designed)
27+
'''
28+
29+
from math import sqrt
30+
31+
t = int(input())
32+
while t:
33+
a, b = map(int, input().split())
34+
for i in range(a, b+1):
35+
flag = True
36+
if i > 1:
37+
for j in range(2, int(sqrt(i)) + 1):
38+
if not i % j:
39+
flag = False
40+
break
41+
if flag:
42+
print(i)
43+
t -= 1

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /