-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNational_project.java
More file actions
159 lines (142 loc) · 3.8 KB
/
National_project.java
File metadata and controls
159 lines (142 loc) · 3.8 KB
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
import java.util.*;
import java.io.*;
/*
https://codeforces.com/problemset/problem/1303/B
*/
public class National_project {
public static void main(String[] str) {
boolean muiltTestCases = true;
var cin = new FastScanner();
PrintWriter cout = new PrintWriter(new BufferedOutputStream(System.out));
int n = 1;
if (muiltTestCases)
n = cin.nextInt();
var s = new testCaseSolution(cin, cout);
while (n-- > 0)
s.solve();
cout.flush();
}
}
class testCaseSolution {
private int[][] mem;
private FastScanner cin;
PrintWriter cout;
public testCaseSolution(FastScanner cin, PrintWriter cout) {
this.cin = cin;
this.cout = cout;
}
class elem implements Comparable<elem>{
public int value;
public int index;
public elem(int value,int index)
{
this.value=value;
this.index=index;
}
public int compareTo(elem e)
{
return Integer.compare(this.value, e.value);
}
}
void solve() {
long n=cin.nextInt();
long g=cin.nextInt(),b=cin.nextInt();
long min_good=n/2;
if(n%2!=0)min_good++;
long x=(n/2)/g;
if(x*2*g!=n)x++;
long min_bad_blocks=x-1;
long ans=min_bad_blocks*b+min_good;
System.out.println(ans<n?n:ans);
}
}
final class Algo {
private Algo() {
}
// O(log(n))
public static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
// O(log(sqrt(n))
public static TreeSet<Integer> getDivisors(int n) {
var st = new TreeSet<Integer>();
for (int i = 1; i * i <= n; i++) {
if (n % i == 0)
st.add(i);
if (n % (n / i) == 0)
st.add(n / i);
}
return st;
}
// O(n(log(log(N)))
public static ArrayList<Integer> primesTill_N(int n) {
var ans = new ArrayList<Integer>();
var prime = new ArrayList<Integer>(n + 1);
for (int i = 0; i < n + 1; i++)
prime.add(1);
for (int p = 2; p * p <= n; p++) {
if (prime.get(p) == 1) {
for (int i = p * p; i <= n; i += p)
prime.set(i, 0);
}
}
for (int p = 2; p <= n; p++)
if (prime.get(p) == 1)
ans.add(p);
return ans;
}
// O(sqrt(N))
public static TreeMap<Integer, Integer> getPrimeFactors(int n) {
var ans = new TreeMap<Integer, Integer>();
var primes = primesTill_N((int) (Math.sqrt(n) + 1));
for (int p : primes) {
while (n % p == 0) {
ans.putIfAbsent(p, 0);
ans.put(p, ans.get(p) + 1);
n /= p;
}
}
if (n > 2) {
ans.putIfAbsent(n, 0);
ans.put(n, ans.get(n) + 1);
}
return ans;
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}