QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#319909#8167. Yet Another Simple Math ProblemfxhdTL 17ms3740kbC++171009b2024-02-03 11:49:242024-02-03 11:49:25

Judging History

你现在查看的是最新测评结果

  • [2024-02-03 11:49:25]
  • 评测
  • 测评结果:TL
  • 用时:17ms
  • 内存:3740kb
  • [2024-02-03 11:49:24]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#ifdef DEBUG
  #include "debug.hpp"
#else
  #define dbg(...) 0
#endif

int floor_sqrt(int64_t x) {
  int64_t low = 1, high = 2000000000;
  while ((low + 1) < high) {
    int64_t mid = (low + high) >> 1;
    if ((mid * mid) > x) {
      high = mid;
    }
    else {
      low = mid;
    }
  }
  return low;
}

int64_t solve(int64_t N) {
  int s = floor_sqrt(N);
  int64_t ans = (s - 1) * int64_t(s - 1);
  int r = N - s * int64_t(s);
  int low = 0, high = r + 1;
  while ((low + 1) < high) {
    int mid = (low + high) >> 1;
    if ((mid * int64_t(mid) + s) <= N) {
      low = mid;
    }
    else {
      high = mid;
    }
  }
  ans += 2 * low;
  if ((s * int64_t(s + 1)) <= N) ans--;
  return ans;
}

void test_case() {
  int64_t N;
  cin >> N;
  cout << solve(N) << '\n';
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    test_case();
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3604kb

input:

3
6
1
101

output:

4
0
83

result:

ok 3 tokens

Test #2:

score: 0
Accepted
time: 17ms
memory: 3668kb

input:

100000
73697
33010
17110
47753
12905
6499
31281
81851
77880
81156
73047
17517
37475
77689
74726
65569
63357
6041
61519
88597
1857
65620
55973
56676
28171
88517
65432
20685
41538
92074
39812
86863
83657
14646
76700
47385
10860
39669
52855
22282
53629
751
99085
6000
22003
31593
99242
61157
17982
91695...

output:

73412
32761
16900
47524
12769
6400
30976
81335
77362
80656
72655
17347
37249
77284
74378
65091
63001
5929
61039
88209
1780
65193
55696
56233
27889
88209
65025
20449
41209
91734
39601
86436
83216
14410
76176
47089
10697
39340
52441
22066
53361
720
98596
5918
21807
31329
98630
60812
17741
91204
6889
4...

result:

ok 100000 tokens

Test #3:

score: 0
Accepted
time: 17ms
memory: 3740kb

input:

100000
160180
187088
148262
131783
150002
191047
129104
182104
184772
178235
186435
138698
127656
123653
177758
100482
125119
167843
124055
103132
152479
104642
194899
132355
123847
193194
194873
178916
175841
117262
129672
150143
127638
194555
138335
172329
140523
110097
162171
109223
181161
175245...

output:

159561
186624
147530
131072
149462
190252
128610
181476
184041
177543
185761
138269
127150
123201
177241
99856
124609
167281
123503
102582
152079
104310
194436
131769
123201
192721
194384
178084
175284
116877
129025
149744
127114
193748
137641
171604
139876
109561
161604
108887
180625
174724
174724
...

result:

ok 100000 tokens

Test #4:

score: 0
Accepted
time: 14ms
memory: 3736kb

input:

100000
238477
256863
242340
219760
228952
207769
262740
218587
206771
293488
260702
275398
285009
280986
276277
288379
206627
233898
269368
289359
297756
296868
207800
228187
234948
285577
283037
262580
249030
256755
293865
276867
208279
275761
239079
268814
257050
254116
230023
222294
232350
268703...

output:

237835
256036
241633
219024
228465
207025
262144
218089
206116
292681
260100
274576
284089
280013
275625
287316
206116
233289
268338
288369
297025
295936
207025
227529
234256
284931
281987
261993
248062
256036
292883
276007
207711
274848
238144
268269
256038
253209
229441
221806
231413
268047
210681...

result:

ok 100000 tokens

Test #5:

score: -100
Time Limit Exceeded

input:

100000
999999997999951124
999999998000044057
999999997999964982
999999997999968201
999999997999963700
999999997999996275
999999997999971870
999999997999963885
999999997999977051
999999997999952461
999999997999994767
999999998000039863
999999998000026619
999999997999958630
999999997999950140
99999999...

output:


result: