QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#700340#5301. Modulo Ruins the Legendtsogsummit#WA 0ms3640kbC++141.6kb2024-11-02 12:45:152024-11-02 12:45:17

Judging History

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

  • [2024-11-02 12:45:17]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3640kb
  • [2024-11-02 12:45:15]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>

#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair

ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            while (n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if (n > 1)
        result -= result / n;
    return result;
}

using namespace std;

ll gcd(ll a, ll b) {
    if(b == 0)
        return a;
    return gcd(b, a % b);
}



ll binpow(ll a, ll b , ll mod) {
    ll res = 1;
    a %= mod;
    while(b > 0) {
        if(b & 1){
            res = res * a;
            res %= mod;
        }
        a = a * a;
        a %= mod;
        b >>= 1;
    }
    return res % mod;
}

int main(){
    long long n , m , i;
    cin >> n >> m;
    long long sum = 0 , a;
    for(i = 0 ; i < n ; i ++){
        cin >> a;
        sum += a;
    }
    long long k = gcd(gcd(n , n*(n + 1)/ 2) , m);
    
    long long res = sum % k;
    cout << res << '\n';//hariu;
    long long resres;
    if(gcd(n *(n + 1) / 2, m) == k) {
        resres = binpow(n*(n + 1)/2/k, phi(m/k) - 1, m/k);
        cout << resres << ' ';
        res -= sum;
        while(res < 0)res += m;
        cout << "0 " << (resres * 1ll * res / k) % (m / k);
    }
    else{
        resres = binpow(n/k , phi(m/k) - 1, m/k);
        cout << resres << ' ';
        res -= sum;
        while(res < 0)res += m;
        cout << (resres * 1ll * res / k) % (m / k) << " 0";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6 24
1 1 4 5 1 4

output:

1
7 0 5

result:

wrong answer Result not equal to solution.