Skip to content

Commit 38f7c20

Browse files
author
IsHYuhi
committed
add D.pys
1 parent e8ae251 commit 38f7c20

File tree

3 files changed

+90
-3
lines changed

3 files changed

+90
-3
lines changed

ABC/ABC168/D.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#Accepted with PyPy3(7.3.0)
2+
#Wrong Answer with Python3(3.8.2)
3+
4+
import heapq
5+
6+
class Edge():
7+
def __init__(self, to, cost):
8+
self.to = to
9+
self.cost = cost
10+
11+
class Pair():
12+
def __init__(self, first, second):#first: 最短距離, second: 頂点番号
13+
self.first = first
14+
self.second = second
15+
16+
def __lt__(self, other):
17+
return (self.first ,self.second) < (other.first, other.second)
18+
19+
def dijkstra(s):
20+
heapq.heapify(que)
21+
d[s] = 0
22+
token[s] = 0
23+
heapq.heappush(que, Pair(0, s))
24+
25+
while que:
26+
p = heapq.heappop(que)
27+
v = p.second
28+
if d[v] < p.first:
29+
continue
30+
for i in range(len(G[v])):
31+
e = G[v][i]
32+
if d[e.to] > d[v] + e.cost:
33+
d[e.to] = d[v] + e.cost
34+
token[e.to] = v
35+
heapq.heappush(que, Pair(d[e.to], e.to))
36+
37+
n, m = map(int, input().split())
38+
39+
G = [[] for _ in range(n)]
40+
for i in range(m):
41+
a, b = map(int, input().split())
42+
G[a-1].append(Edge(b-1, 1))
43+
G[b-1].append(Edge(a-1, 1))
44+
45+
d = [float('inf')]*n
46+
token = [0]*n
47+
que = []
48+
dijkstra(0)
49+
50+
if float('inf') not in d:
51+
print('Yes')
52+
for i in range(1, n):
53+
print(token[i]+1)
54+
else:
55+
print('No')

ABC/ABC169/D.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import bisect
2+
def factorization(n):
3+
if n == 1:
4+
return []
5+
arr = []
6+
temp = n
7+
for i in range(2, int(-(-n**0.5//1))+1):
8+
if temp%i==0:
9+
cnt=0
10+
while temp%i==0:
11+
cnt+=1
12+
temp //= i
13+
arr.append([i, cnt])
14+
15+
if temp!=1:
16+
arr.append([temp, 1])
17+
18+
if arr==[]:
19+
arr.append([n, 1])
20+
21+
return arr
22+
23+
n = int(input())
24+
25+
sigma = [1]
26+
for i in range(2, 20):
27+
sigma.append(i+sigma[i-2])
28+
ans = 0
29+
for i, j in factorization(n):
30+
ans += bisect.bisect_right(sigma, j)
31+
32+
print(ans)

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ AtCoderの問題をpython3で解いたものになります。AC確認は行っ
88
## [AtCoder Beginner Contest](ABC)
99
| Problem A | Problem B | Problem C | Problem D | Problem E | Problem F |
1010
|:---:|:---:|:---:|:---:|:---:|:---:|
11-
|179/179|177/179|121/179|25/173|1/54|0/54|
11+
|179/179|177/179|121/179|27/173|1/54|0/54|
1212

1313
### ABC001 - ABC041
1414
|コンテスト| A | B | C | D ||コンテスト| A | B | C | D |
@@ -87,8 +87,8 @@ AtCoderの問題をpython3で解いたものになります。AC確認は行っ
8787
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
8888
[ABC126](ABC/ABC126)|[&check;](ABC/ABC126/A.py)|[&check;](ABC/ABC126/B.py)|[&check;](ABC/ABC126/C.py)|||||[ABC166](ABC/ABC166)|[&check;](ABC/ABC166/A.py)|[&check;](ABC/ABC166/B.py)|[&check;](ABC/ABC166/C.py)|[&check;](ABC/ABC166/D.py)|||
8989
[ABC127](ABC/ABC127)|[&check;](ABC/ABC127/A.py)|[&check;](ABC/ABC127/B.py)|[&check;](ABC/ABC127/C.py)|||||[ABC167](ABC/ABC167)|[&check;](ABC/ABC167/A.py)|[&check;](ABC/ABC167/B.py)|[&check;](ABC/ABC167/C.py)|[&check;](ABC/ABC167/D.py)|||
90-
[ABC128](ABC/ABC128)|[&check;](ABC/ABC128/A.py)|[&check;](ABC/ABC128/B.py)||||||[ABC168](ABC/ABC168)|[&check;](ABC/ABC168/A.py)|[&check;](ABC/ABC168/B.py)|[&check;](ABC/ABC168/C.py)||||
91-
[ABC129](ABC/ABC129)|[&check;](ABC/ABC129/A.py)|[&check;](ABC/ABC129/B.py)|[&check;](ABC/ABC129/C.py)|||||[ABC169](ABC/ABC169)|[&check;](ABC/ABC169/A.py)|[&check;](ABC/ABC169/B.py)|[&check;](ABC/ABC169/C.py)||||
90+
[ABC128](ABC/ABC128)|[&check;](ABC/ABC128/A.py)|[&check;](ABC/ABC128/B.py)||||||[ABC168](ABC/ABC168)|[&check;](ABC/ABC168/A.py)|[&check;](ABC/ABC168/B.py)|[&check;](ABC/ABC168/C.py)|[&check;](ABC/ABC168/D.py)|||
91+
[ABC129](ABC/ABC129)|[&check;](ABC/ABC129/A.py)|[&check;](ABC/ABC129/B.py)|[&check;](ABC/ABC129/C.py)|||||[ABC169](ABC/ABC169)|[&check;](ABC/ABC169/A.py)|[&check;](ABC/ABC169/B.py)|[&check;](ABC/ABC169/C.py)|[&check;](ABC/ABC169/D.py)|||
9292
[ABC130](ABC/ABC130)|[&check;](ABC/ABC130/A.py)|[&check;](ABC/ABC130/B.py)|[&check;](ABC/ABC130/C.py)|||||[ABC170](ABC/ABC170)|[&check;](ABC/ABC170/A.py)|[&check;](ABC/ABC170/B.py)|[&check;](ABC/ABC170/C.py)||||
9393
|[ABC131](ABC/ABC131)|[&check;](ABC/ABC131/A.py)|[&check;](ABC/ABC131/B.py)|[&check;](ABC/ABC131/C.py)|[&check;](ABC/ABC131/D.py)||||[ABC171](ABC/ABC171)|[&check;](ABC/ABC171/A.py)|[&check;](ABC/ABC171/B.py)|[&check;](ABC/ABC171/C.py)|[&check;](ABC/ABC171/D.py)|||
9494
|[ABC132](ABC/ABC132)|[&check;](ABC/ABC132/A.py)|[&check;](ABC/ABC132/B.py)|[&check;](ABC/ABC132/C.py)|||||[ABC172](ABC/ABC172)|[&check;](ABC/ABC172/A.py)|[&check;](ABC/ABC172/B.py)|||||

0 commit comments

Comments
 (0)