QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#267339#3278. 算术djwj2330 0ms3748kbC++141.5kb2023-11-27 10:06:212023-11-27 10:06:23

Judging History

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

  • [2023-11-27 10:06:23]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3748kb
  • [2023-11-27 10:06:21]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define fo(v,a,b) for(int v = a; v <= b; v++)
#define fr(v,a,b) for(int v = a; v >= b; v--)
#define cl(a,v) memset(a, v, sizeof(a))

typedef long long ll;

ll mul(ll A, ll B, ll P){
	ll C = A * B - (ll)((double)A * B / P + 0.1) * P;
	return C < 0 ? C + P : C;
}
ll power(ll a, ll x, ll P) {
    ll res = 1;
    while(x) {
        if(x & 1LL) res = mul(res, a, P);
        a = mul(a, a, P), x >>= 1;
    } return res;
}

const int N = 110;

ll pr[N]; int q[N], cc;

void Divide(ll P) {
    cc = 0, cl(pr, 0), cl(q, 0);
    for(int i = 2; (ll)i * i <= P; i++)
        if(P % i == 0) {
            cc++, pr[cc] = i;
            while(P % i == 0) P /= i, q[cc]++;
        }
    if(P > 1) pr[++cc] = P, q[cc] = 1;
}

ll b, P, phiP, ans;

void Main() {
    scanf("%lld", &b);
    if(__gcd(b, P) != 1) return puts("-1"), void();

    ans = phiP;
    fo(i, 1, cc) {
        while(ans % pr[i] == 0) {
            if(power(b, ans / pr[i], P) == 1)
                ans /= pr[i];
            else break;
        }
    }
    if(ans & 1) return puts("-1"), void();
    ll d = ans / 2;
    if(power(b, d, P) != P - 1) return puts("-1"), void();
    printf("%lld\n", d - 1);
}

int main()
{
    int T; scanf("%d%lld", &T, &P);

    Divide(P), phiP = 1;
    fo(i, 1, cc) {
        phiP *= pr[i] - 1;
        fo(j, 2, q[i]) phiP *= pr[i];
    }
    Divide(phiP);

    while(T--) Main();

    return 0;
}
/*
 
*/

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3748kb

input:

10 3
10
7
13
4
17
28
29
13
4
30

output:

-1
-1
-1
-1
0
-1
0
-1
-1
-1

result:

wrong answer 5th numbers differ - expected: '2', found: '0'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%

Subtask #8:

score: 0
Skipped

Dependency #1:

0%

Subtask #9:

score: 0
Skipped

Dependency #1:

0%

Subtask #10:

score: 0
Skipped

Dependency #1:

0%