QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#947#242289#7044. Easy ProblemN_z_AnwarSuccess!2024-10-11 10:21:492024-10-11 10:21:49

詳細信息

Extra Test:

Runtime Error

input:

20
6065024 1 85063 2858
41823157 6 1 131956226
38195233 57 13 1240589
9264907 2 3 4420
20692482 3 1 7
14748034 1 1 2500
36294646 6409 90 124962888
18077776 84782 61 1
41575423 1 3873 52678341
40057392 52 69844 81134
7184482 5 3888 367110341
2689202 4119 27813 41837291
59430486 96 7 590
11700767 1 28...

output:


result:


ID题目提交者结果用时内存语言文件大小提交时间测评时间
#242289#7044. Easy ProblemAnwarRE 167ms5588kbC++201.7kb2023-11-07 06:31:102024-10-11 10:22:04

answer

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int N = 1e5 + 5 , MOD =  1e9 + 7;

ll power(ll x , ll y , ll MOD )
{
    ll res =1;
    while ( y )
    {
        if( y&1 ) res = res * x % MOD  ;

        y >>= 1;
        x = x * x % MOD ;
    }

    return res;
}

int32_t main() {

    cin.tie(0);cin.sync_with_stdio(0);
    cout.tie(0);cout.sync_with_stdio(0);


    ll phi = 1;

    int nn = 59964251 ;
    for(int i = 2 , d= 1 ; i*i <= nn ; i+=d , d = 2)
    {
        if(nn%i == 0)
        {
            ll p_to_k = 1;
            while(nn%i == 0) p_to_k *= i , nn /= i ;
            phi *= (p_to_k/i ) * (i-1) ;
        }
    }

    if(nn > 1) phi *= nn-1;


    int t =1;
    cin >> t;
    while (t--)
    {
        string n ;

        int m , d , k ;
        cin >> n >> m >> d >> k ;

        ll po[m+1] ;
        po[0] = 1 ;
        for(int i= 1; i <= m ; i++) po[i] = power( i , k ,59964251 ) ;

        ll sum[m+1] ;
        sum[0] =0 ;
        for(int i= 1; i <= m ;i++) sum[i] = (sum[i-1] + po[i]) % 59964251 ;

        int exp =0 ;

        for(char c : n) exp *= 10 , exp += (c - '0' ) , exp %= phi ;

        for(int i =1;  i<= m ;i++) sum[i] = power( sum[i] , exp + phi ,  59964251 ) ;

        vector<int> ans(m+1) ;

        for(int i= m ; i >= d ; i--)
        {
            if( i%d ) continue;

            ans[i] = sum[ m/i ] * power( power( i , k , 59964251 ) , exp + phi , 59964251) % 59964251 ;

            for(int j = i +i ; j <= m ; j += i) ans[i] -= ans[j] , ans[i] += 59964251 , ans[i] %= 59964251 ;

        }

        cout << ans[d]  << "\n" ;
    }

    return 0;
}