UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214378#2678. Small MultipleThySecret100335ms7272kbC++111.6kb2024-11-18 19:11:402024-11-19 08:27:25

answer

#include <bits/stdc++.h>

using namespace std;

// #define int long long
#define x first
#define y second
#define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)

inline void debug() { cerr << '\n'; }
template<typename Type, typename... Other>
inline void debug(const Type& x, const Other&... y) { cerr << x << ' '; debug(y...); }
#define DEBUG(a...) cerr << "[" << #a << "] = ", debug(a);

typedef long long LL;
typedef pair<int, int> PII;

const int N = 1000010;
const int INF = 0x3f3f3f3f;

template<typename Type>
inline void read(Type &res)
{
    res = 0;
    int ch = getchar(), flag = 0;
    while (!isdigit(ch)) flag |= ch == '-', ch = getchar();
    while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
    res = flag ? -res : res;
}
template<typename Type, typename... Other>
inline void read(Type &res, Other&... y) { read(res), read(y...); }

int k, m, ans;
deque<PII> dq;
bool vis[N];

signed main()
{
	// ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> k >> m;

    dq.push_front({1, 1});
    vis[1] = true;
    
    while (!dq.empty())
    {
        // auto [cur, val] = dq.front(); dq.pop_front();
        PII x = dq.front(); dq.pop_front();
        int cur = x.x, val = x.y;
        // int cur = dq.front().x, val = dq.front().y; dq.pop_front();
        if (!cur) return cout << val << '\n', 0;
        if (!vis[cur * m % k])
        {
            dq.push_front({cur * m % k, val});
            vis[cur * m % k] = true;
        }
        if (!vis[(cur + 1) % k])
            dq.push_back({(cur + 1) % k, val + 1});
    }

	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 5
Accepted
time: 1ms
memory: 1248kb

input:

32 4

output:

1

result:

ok single line: '1'

Test #2:

score: 5
Accepted
time: 0ms
memory: 1248kb

input:

25 6

output:

5

result:

ok single line: '5'

Test #3:

score: 5
Accepted
time: 0ms
memory: 1244kb

input:

19 3

output:

2

result:

ok single line: '2'

Test #4:

score: 5
Accepted
time: 0ms
memory: 1248kb

input:

64 7

output:

4

result:

ok single line: '4'

Test #5:

score: 5
Accepted
time: 0ms
memory: 1244kb

input:

86 10

output:

3

result:

ok single line: '3'

Test #6:

score: 5
Accepted
time: 1ms
memory: 1248kb

input:

17 2

output:

2

result:

ok single line: '2'

Test #7:

score: 5
Accepted
time: 37ms
memory: 7272kb

input:

937761 10

output:

6

result:

ok single line: '6'

Test #8:

score: 5
Accepted
time: 3ms
memory: 2668kb

input:

788944 8

output:

4

result:

ok single line: '4'

Test #9:

score: 5
Accepted
time: 22ms
memory: 3932kb

input:

573314 3

output:

4

result:

ok single line: '4'

Test #10:

score: 5
Accepted
time: 28ms
memory: 5044kb

input:

785883 5

output:

2

result:

ok single line: '2'

Test #11:

score: 5
Accepted
time: 36ms
memory: 5064kb

input:

769025 7

output:

6

result:

ok single line: '6'

Test #12:

score: 5
Accepted
time: 17ms
memory: 4660kb

input:

909894 4

output:

3

result:

ok single line: '3'

Test #13:

score: 5
Accepted
time: 36ms
memory: 6032kb

input:

585472 9

output:

8

result:

ok single line: '8'

Test #14:

score: 5
Accepted
time: 0ms
memory: 2284kb

input:

795020 5

output:

4

result:

ok single line: '4'

Test #15:

score: 5
Accepted
time: 6ms
memory: 2800kb

input:

514716 8

output:

3

result:

ok single line: '3'

Test #16:

score: 5
Accepted
time: 36ms
memory: 6176kb

input:

984458 5

output:

4

result:

ok single line: '4'

Test #17:

score: 5
Accepted
time: 27ms
memory: 4128kb

input:

645285 2

output:

4

result:

ok single line: '4'

Test #18:

score: 5
Accepted
time: 42ms
memory: 6720kb

input:

694328 9

output:

8

result:

ok single line: '8'

Test #19:

score: 5
Accepted
time: 13ms
memory: 3816kb

input:

698907 6

output:

2

result:

ok single line: '2'

Test #20:

score: 5
Accepted
time: 30ms
memory: 6164kb

input:

994036 7

output:

2

result:

ok single line: '2'