QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#34226 | #4248. Number Theory | sinbad | AC ✓ | 8ms | 3820kb | C++17 | 4.1kb | 2022-06-06 08:22:50 | 2022-06-06 09:58:01 |
Judging History
answer
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const multiset<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
template <class T> auto vect(const T& v, int n) { return vector<T>(n, v); }
template <class T, class... D> auto vect(const T& v, int n, D... m) {
return vector<decltype(vect(v, m...))>(n, vect(v, m...));
}
using int64 = long long;
using int128 = __int128_t;
using ii = pair<int, int>;
#define SZ(x) (int)((x).size())
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
// mt19937 mrand(random_device{}());
// int rnd(int x) { return mrand() % x; }
mt19937_64 mrand(random_device{}());
int64 rnd(int64 x) { return mrand() % x; }
int lg2(int64 x) { return sizeof(int64) * 8 - 1 - __builtin_clzll(x); }
template <class T> void out(const vector<T>& a) { for (int i = 0; i < SZ(a); ++i) cout << a[i] << " \n"[i + 1 == SZ(a)]; }
template <class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template <class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template <class T> void dedup(vector<T>& v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); }
void add_mod(int& x, int y) { x += y; if (x >= MOD) x -= MOD; }
void sub_mod(int& x, int y) { x += MOD - y; if (x >= MOD) x -= MOD; }
struct fast_ios {
fast_ios() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
};
} fast_ios_;
int main() {
int p;
cin >> p;
vector<int> dp(p, -1);
for (int x = p - 1; x >= 0; --x) {
dp[1LL * x * x % p] = x;
}
int best = 0;
for (int r = 0; r < p; ++r) {
int cur = 0;
for (int x = 0; x < 50; ++x) {
int t = (r + p - 1LL * x * x % p) % p;
if (dp[t] >= 0) {
cur = x;
break;
}
}
ckmax(best, cur);
}
cout << best << '\n';
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 3564kb
input:
2
output:
0
result:
ok 1 number(s): "0"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 2ms
memory: 3640kb
input:
5
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 2ms
memory: 3668kb
input:
7
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 8ms
memory: 3612kb
input:
99991
output:
20
result:
ok 1 number(s): "20"
Test #6:
score: 0
Accepted
time: 3ms
memory: 3600kb
input:
17041
output:
13
result:
ok 1 number(s): "13"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3788kb
input:
25343
output:
12
result:
ok 1 number(s): "12"
Test #8:
score: 0
Accepted
time: 1ms
memory: 3692kb
input:
37309
output:
15
result:
ok 1 number(s): "15"
Test #9:
score: 0
Accepted
time: 5ms
memory: 3532kb
input:
58027
output:
15
result:
ok 1 number(s): "15"
Test #10:
score: 0
Accepted
time: 5ms
memory: 3604kb
input:
47843
output:
19
result:
ok 1 number(s): "19"
Test #11:
score: 0
Accepted
time: 4ms
memory: 3564kb
input:
33857
output:
14
result:
ok 1 number(s): "14"
Test #12:
score: 0
Accepted
time: 5ms
memory: 3708kb
input:
58921
output:
18
result:
ok 1 number(s): "18"
Test #13:
score: 0
Accepted
time: 7ms
memory: 3556kb
input:
90821
output:
14
result:
ok 1 number(s): "14"
Test #14:
score: 0
Accepted
time: 5ms
memory: 3648kb
input:
51749
output:
14
result:
ok 1 number(s): "14"
Test #15:
score: 0
Accepted
time: 3ms
memory: 3768kb
input:
16223
output:
14
result:
ok 1 number(s): "14"
Test #16:
score: 0
Accepted
time: 6ms
memory: 3560kb
input:
75503
output:
15
result:
ok 1 number(s): "15"
Test #17:
score: 0
Accepted
time: 4ms
memory: 3780kb
input:
29287
output:
15
result:
ok 1 number(s): "15"
Test #18:
score: 0
Accepted
time: 3ms
memory: 3528kb
input:
75653
output:
14
result:
ok 1 number(s): "14"
Test #19:
score: 0
Accepted
time: 2ms
memory: 3648kb
input:
61667
output:
17
result:
ok 1 number(s): "17"
Test #20:
score: 0
Accepted
time: 5ms
memory: 3644kb
input:
57773
output:
20
result:
ok 1 number(s): "20"
Test #21:
score: 0
Accepted
time: 6ms
memory: 3500kb
input:
82009
output:
17
result:
ok 1 number(s): "17"
Test #22:
score: 0
Accepted
time: 3ms
memory: 3632kb
input:
24251
output:
14
result:
ok 1 number(s): "14"
Test #23:
score: 0
Accepted
time: 7ms
memory: 3608kb
input:
99733
output:
17
result:
ok 1 number(s): "17"
Test #24:
score: 0
Accepted
time: 2ms
memory: 3664kb
input:
25849
output:
15
result:
ok 1 number(s): "15"
Test #25:
score: 0
Accepted
time: 3ms
memory: 3564kb
input:
72949
output:
18
result:
ok 1 number(s): "18"
Test #26:
score: 0
Accepted
time: 3ms
memory: 3756kb
input:
93523
output:
16
result:
ok 1 number(s): "16"
Test #27:
score: 0
Accepted
time: 6ms
memory: 3636kb
input:
75577
output:
16
result:
ok 1 number(s): "16"
Test #28:
score: 0
Accepted
time: 2ms
memory: 3556kb
input:
43201
output:
14
result:
ok 1 number(s): "14"
Test #29:
score: 0
Accepted
time: 7ms
memory: 3724kb
input:
99713
output:
20
result:
ok 1 number(s): "20"
Test #30:
score: 0
Accepted
time: 3ms
memory: 3608kb
input:
89563
output:
17
result:
ok 1 number(s): "17"
Test #31:
score: 0
Accepted
time: 5ms
memory: 3628kb
input:
15767
output:
14
result:
ok 1 number(s): "14"
Test #32:
score: 0
Accepted
time: 5ms
memory: 3648kb
input:
52379
output:
16
result:
ok 1 number(s): "16"
Test #33:
score: 0
Accepted
time: 1ms
memory: 3820kb
input:
28663
output:
21
result:
ok 1 number(s): "21"
Test #34:
score: 0
Accepted
time: 2ms
memory: 3656kb
input:
5087
output:
11
result:
ok 1 number(s): "11"
Test #35:
score: 0
Accepted
time: 3ms
memory: 3732kb
input:
24097
output:
14
result:
ok 1 number(s): "14"
Test #36:
score: 0
Accepted
time: 6ms
memory: 3548kb
input:
83047
output:
15
result:
ok 1 number(s): "15"
Test #37:
score: 0
Accepted
time: 6ms
memory: 3564kb
input:
70913
output:
15
result:
ok 1 number(s): "15"
Test #38:
score: 0
Accepted
time: 2ms
memory: 3732kb
input:
8069
output:
17
result:
ok 1 number(s): "17"
Test #39:
score: 0
Accepted
time: 6ms
memory: 3564kb
input:
72937
output:
18
result:
ok 1 number(s): "18"
Test #40:
score: 0
Accepted
time: 3ms
memory: 3572kb
input:
9391
output:
11
result:
ok 1 number(s): "11"
Test #41:
score: 0
Accepted
time: 6ms
memory: 3612kb
input:
63977
output:
15
result:
ok 1 number(s): "15"
Test #42:
score: 0
Accepted
time: 2ms
memory: 3664kb
input:
6779
output:
13
result:
ok 1 number(s): "13"
Test #43:
score: 0
Accepted
time: 2ms
memory: 3620kb
input:
3209
output:
11
result:
ok 1 number(s): "11"
Test #44:
score: 0
Accepted
time: 6ms
memory: 3660kb
input:
77081
output:
21
result:
ok 1 number(s): "21"
Test #45:
score: 0
Accepted
time: 3ms
memory: 3612kb
input:
98533
output:
18
result:
ok 1 number(s): "18"
Test #46:
score: 0
Accepted
time: 4ms
memory: 3652kb
input:
28859
output:
13
result:
ok 1 number(s): "13"
Test #47:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
12907
output:
13
result:
ok 1 number(s): "13"
Test #48:
score: 0
Accepted
time: 3ms
memory: 3648kb
input:
22349
output:
13
result:
ok 1 number(s): "13"
Test #49:
score: 0
Accepted
time: 2ms
memory: 3604kb
input:
11057
output:
13
result:
ok 1 number(s): "13"
Test #50:
score: 0
Accepted
time: 1ms
memory: 3624kb
input:
15809
output:
15
result:
ok 1 number(s): "15"
Test #51:
score: 0
Accepted
time: 2ms
memory: 3720kb
input:
14437
output:
14
result:
ok 1 number(s): "14"
Test #52:
score: 0
Accepted
time: 2ms
memory: 3688kb
input:
163
output:
5
result:
ok 1 number(s): "5"
Test #53:
score: 0
Accepted
time: 7ms
memory: 3532kb
input:
87313
output:
14
result:
ok 1 number(s): "14"
Test #54:
score: 0
Accepted
time: 2ms
memory: 3560kb
input:
761
output:
10
result:
ok 1 number(s): "10"
Test #55:
score: 0
Accepted
time: 3ms
memory: 3556kb
input:
86239
output:
16
result:
ok 1 number(s): "16"
Test #56:
score: 0
Accepted
time: 7ms
memory: 3708kb
input:
90163
output:
17
result:
ok 1 number(s): "17"
Test #57:
score: 0
Accepted
time: 4ms
memory: 3736kb
input:
30859
output:
14
result:
ok 1 number(s): "14"
Test #58:
score: 0
Accepted
time: 2ms
memory: 3604kb
input:
47807
output:
15
result:
ok 1 number(s): "15"
Test #59:
score: 0
Accepted
time: 2ms
memory: 3744kb
input:
7547
output:
11
result:
ok 1 number(s): "11"
Test #60:
score: 0
Accepted
time: 3ms
memory: 3764kb
input:
13327
output:
12
result:
ok 1 number(s): "12"
Test #61:
score: 0
Accepted
time: 4ms
memory: 3612kb
input:
33577
output:
15
result:
ok 1 number(s): "15"
Test #62:
score: 0
Accepted
time: 2ms
memory: 3692kb
input:
127
output:
6
result:
ok 1 number(s): "6"
Test #63:
score: 0
Accepted
time: 4ms
memory: 3648kb
input:
38711
output:
14
result:
ok 1 number(s): "14"
Test #64:
score: 0
Accepted
time: 1ms
memory: 3700kb
input:
8377
output:
11
result:
ok 1 number(s): "11"
Test #65:
score: 0
Accepted
time: 4ms
memory: 3612kb
input:
36607
output:
15
result:
ok 1 number(s): "15"
Test #66:
score: 0
Accepted
time: 3ms
memory: 3532kb
input:
83299
output:
17
result:
ok 1 number(s): "17"
Test #67:
score: 0
Accepted
time: 3ms
memory: 3612kb
input:
14303
output:
16
result:
ok 1 number(s): "16"
Test #68:
score: 0
Accepted
time: 4ms
memory: 3664kb
input:
32003
output:
14
result:
ok 1 number(s): "14"