ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

jzoj 6272. 2019.8.4【NOIP提高组A】整除 (division)

2019-08-14 10:00:32  阅读:204  来源: 互联网

标签:division 6272 2019.8 int 质数 pri ii read define


Description

详见OJ

Solution

先想到了50分暴力,又想到了对于每个质数分开求答案,最后相乘,结果打挂。
正解根据中国剩余定理,可以对于每个质数分开求。
\((x^m-x)\)%\(n=0\)
由于\(n\)有多个不同的质数组成,所以我们可以用中国剩余定理来分解成\(c\)个方程。
然后得到\(x^m-x≡0(mod~p)\)(\(c\)个方程)
我们对于每个都用50分暴力来求,最后答案乘起来即可。
时间\(O(T*c*t*logm)\),80分。
由于有个\(log\),我们考虑优化。
根据积性筛(欧拉筛),我们可以接近\(O(n)\)求出\(1\)~\(n\)的\(m\)次方,在%\(n\)的意义下。
质数直接用\(ksm\)求出\(x^m\),而合数则可以用其质数\(y\)的值和\(x/y\)的值相乘求出。
这样消去\(log\),可以AC了。
有人用\(O(c×logpi)\)的时间过了这题。
在线%%%dalao

Code


#include <cstdio>
#include <cstring>
#define N 51
#define ll long long
#define mo 998244353
#define mem(x, a) memset(x, a, sizeof x)
#define fo(x, a, b) for (int x = a; x <= b; x++)
#define fd(x, a, b) for (int x = a; x >= b; x--)
using namespace std;
int id, T, c, m, n, ans, s1;
int kz[10010], phi[N], pri[10010];

inline int read()
{
    int x = 0; char c = getchar();
    while (c < '0' || c > '9') c = getchar();
    while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
    return x;
}

int ksm(int x, int y)
{
    int s = 1;
    while (y)
    {
        if (y & 1) s = s * x % n;
        x = x * x % n; y >>= 1;
    }
    return s;
}

int main()
{
    freopen("division.in", "r", stdin);
    freopen("division.out", "w", stdout);
    id = read();
    T = read();
    while (T--)
    {
        c = read(), m = read();
        fo(i, 1, c) phi[i] = read();
        ans = 1;
        fo(i, 1, c)
        {
            s1 = 1; n = phi[i];
            fo(ii, 2, n) kz[ii] = 0;
            pri[0] = 0;
            fo(ii, 2, n)
            {
                if (! kz[ii]) kz[ii] = ksm(ii, m), pri[++pri[0]] = ii;
                for (int j = 1; pri[j] * ii <= n; j++)
                {
                    kz[pri[j] * ii] = kz[pri[j]] * kz[ii] % n;
                    if (ii % pri[j] == 0) break;
                }
                if (kz[ii] == ii % n) s1++;
            }
            ans = (ll)ans * s1 % mo;
        }
        printf("%d\n", ans);
    }
    return 0;
}

标签:division,6272,2019.8,int,质数,pri,ii,read,define
来源: https://blog.csdn.net/Larry1118/article/details/98552758

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有