2019广东工业大学新生杯决赛 I-迷途的怪物(2019 Guangdong University of technology freshman Cup final I – lost monster)

题目:I-I-迷途的怪物_2019年广东工业大学腾讯杯新生程序设计竞赛(同步赛) (nowcoder.com)

将(p-1)^n 按照多项式定理拆开,会发现只有一项没有p,其余项都有p,可直接约掉。

因此判断n的奇偶性即可得出答案。(为什么n为奇数时答案时p-1我也不知道,等会了再回来补充qwq)

代码:

#include <iostream>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin >> T;
    while (T--)
    {
        ll p;
        string n;
        cin >> p >> n;
        int t = n[n.size() - 1] - '0';
        if (t % 2 == 0)
            cout << 1 << endl;
        else
            cout << p - 1 << endl;
    }
    return 0;
}
————————

Title: i-i-lost monster_ 2019 Guangdong University of technology Tencent cup freshman program design competition (synchronous competition) (nowcoder. Com)

< strong > if you disassemble (p-1) ^ n according to the polynomial theorem, you will find that only one item has no P, and the other items have p, which can be directly reduced

< strong > therefore, the answer can be obtained by judging the parity of n (why I don’t know when the answer is P-1 when n is an odd number. I’ll come back later to supplement qwq)

code:

#include <iostream>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin >> T;
    while (T--)
    {
        ll p;
        string n;
        cin >> p >> n;
        int t = n[n.size() - 1] - '0';
        if (t % 2 == 0)
            cout << 1 << endl;
        else
            cout << p - 1 << endl;
    }
    return 0;
}