UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214363#2678. Small MultipleThySecret301ms1248kbC++111.6kb2024-11-18 18:45:152024-11-19 08:26:08

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 = 200010;
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: 0ms
memory: 1244kb

input:

32 4

output:

1

result:

ok single line: '1'

Test #2:

score: 5
Accepted
time: 1ms
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: 0ms
memory: 1244kb

input:

17 2

output:

2

result:

ok single line: '2'

Test #7:

score: 0
Runtime Error

input:

937761 10

output:


result:


Test #8:

score: 0
Runtime Error

input:

788944 8

output:


result:


Test #9:

score: 0
Runtime Error

input:

573314 3

output:


result:


Test #10:

score: 0
Runtime Error

input:

785883 5

output:


result:


Test #11:

score: 0
Runtime Error

input:

769025 7

output:


result:


Test #12:

score: 0
Runtime Error

input:

909894 4

output:


result:


Test #13:

score: 0
Runtime Error

input:

585472 9

output:


result:


Test #14:

score: 0
Runtime Error

input:

795020 5

output:


result:


Test #15:

score: 0
Runtime Error

input:

514716 8

output:


result:


Test #16:

score: 0
Runtime Error

input:

984458 5

output:


result:


Test #17:

score: 0
Runtime Error

input:

645285 2

output:


result:


Test #18:

score: 0
Runtime Error

input:

694328 9

output:


result:


Test #19:

score: 0
Runtime Error

input:

698907 6

output:


result:


Test #20:

score: 0
Runtime Error

input:

994036 7

output:


result: