-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
217 lines (178 loc) · 3.95 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package main
import (
"bufio"
"fmt"
"math"
"math/bits"
"os"
"strconv"
"strings"
)
// INF は最大値を表す数
const INF = int(1e9)
func main() {
A, B, C := nextInt3()
for i := 1; i < 10000; i++ {
if (A*i)%B == C {
fmt.Println("YES")
return
}
}
fmt.Println("NO")
}
func gcd(a, b int) int {
if b > a {
a, b = b, a
}
for b != 0 {
a, b = b, a%b
}
return a
}
func debug(args ...interface{}) {
fmt.Fprintln(os.Stderr, args...)
}
// ==================================================
// 入力操作
// ==================================================
var stdin = initStdin()
func initStdin() *bufio.Scanner {
bufsize := 1 * 1024 * 1024 // 1 MB
var stdin = bufio.NewScanner(os.Stdin)
stdin.Buffer(make([]byte, bufsize), bufsize)
stdin.Split(bufio.ScanWords)
return stdin
}
func nextString() string {
stdin.Scan()
return stdin.Text()
}
// 遅いから極力使わない。
func nextBytes() []byte {
return []byte(nextString())
}
func nextInt() int {
i, _ := strconv.Atoi(nextString())
return i
}
func nextInt2() (int, int) {
return nextInt(), nextInt()
}
func nextInt3() (int, int, int) {
return nextInt(), nextInt(), nextInt()
}
func nextInt4() (int, int, int, int) {
return nextInt(), nextInt(), nextInt(), nextInt()
}
func nextInts(n int) []int {
a := make([]int, n)
for i := 0; i < n; i++ {
a[i] = nextInt()
}
return a
}
// toi は byteの数値をintに変換します。
func toi(b byte) int {
return int(b - '0')
}
func nextLongIntAsArray() []int {
s := nextString()
l := len(s)
arr := make([]int, l)
for i := 0; i < l; i++ {
arr[i] = toi(s[i])
}
return arr
}
func nextFloat() float64 {
f, _ := strconv.ParseFloat(nextString(), 64)
return f
}
// ==================================================
// 数値操作
// ==================================================
// max は aとbのうち大きい方を返します。
func max(a, b int) int {
if a > b {
return a
}
return b
}
// min は aとbのうち小さい方を返します。
func min(a, b int) int {
if a < b {
return a
}
return b
}
// abs は aの絶対値を返します。
func abs(a int) int {
if a > 0 {
return a
}
return -a
}
// pow は aのb乗を返します。
func pow(a, b int) int {
return int(math.Pow(float64(a), float64(b)))
}
// binarysearch は judgeがtrueを返す最小の数値を返します。
func binarysearch(ok, ng int, judge func(int) bool) int {
for abs(ok-ng) > 1 {
mid := (ok + ng) / 2
if judge(mid) {
ok = mid
} else {
ng = mid
}
}
return ok
}
// ch は condがtrueのときok, falseのときngを返します。
func ch(cond bool, ok, ng int) int {
if cond {
return ok
}
return ng
}
// ==================================================
// ビット操作
// ==================================================
// nthbit はaのn番目のビットを返します。
func nthbit(a int, n int) int { return int((a >> uint(n)) & 1) }
// popcount はaのうち立っているビットを数えて返します。
func popcount(a int) int {
return bits.OnesCount(uint(a))
}
// ==================================================
// 文字列操作
// ==================================================
// toLowerCase は sをすべて小文字にした文字列を返します。
func toLowerCase(s string) string {
return strings.ToLower(s)
}
// toUpperCase は sをすべて大文字にした文字列を返します。
func toUpperCase(s string) string {
return strings.ToUpper(s)
}
// isLower はbが小文字かどうかを判定します
func isLower(b byte) bool {
return 'a' <= b && b <= 'z'
}
// isUpper はbが大文字かどうかを判定します
func isUpper(b byte) bool {
return 'A' <= b && b <= 'Z'
}
// ==================================================
// 構造体
// ==================================================
// Point は 座標を表す構造体です。
type Point struct {
x int
y int
}
// Pointf は座標を表す構造体です。
type Pointf struct {
x float64
y float64
}