牛客小白月赛14(部分题解)

牛客小白月赛14(部分题解)_第1张图片

#include
#include
using namespace std;
#define ll long long
const ll mod = 998244353;
ll n,k,p;
ll pow_m(ll a,ll k,ll p)
{
    ll ans=1;
    ll tmp=a%p;
    while(k)
    {
        if(k&1)ans=ans*tmp%p;
        tmp=tmp*tmp%p;
        k>>=1;
    }
    return ans;
}
ll C(ll n,ll m,ll p)
{
    if(m>n)return 0;
    ll a=1,b=1;
    for(int i=1;i<=m;i++)
    {
        a=a*(n+i-m)%p;
        b=b*i%p;
    }
    return a*pow_m(b,p-2,p)%p;
}
int main()
{
    scanf("%lld %lld %lld", &n, &k, &p);
    ll ans = 0;
    ll temp = C(n, k, mod);
    for(ll i = k ; i <= n ; ++ i){
        ans = (ans%mod + (temp*pow_m(p,i,mod)%mod)*pow_m(1-p,n-i,mod)%mod) % mod;
        temp = (((temp * (n-i))%mod)*pow_m(i+1, mod-2, mod))%mod;
    }
    cout << (ans + mod) % mod << endl;
    return 0;
}


牛客小白月赛14(部分题解)_第2张图片

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
#define endl '\n'
const double pi = acos(-1);
const int maxn = 1e5 + 10;
const int maxm = 5e5 + 10;
const int mod = 104857601;
int n, k;
int a[maxn];
int main()
{
    scanf("%d", &n);
    if(n % 2==0) cout << "2";
    else cout <<"1";
    return 0;
}

牛客小白月赛14(部分题解)_第3张图片

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
#define endl '\n'
const double pi = acos(-1);
const int maxn = 1e5 + 10;
const int maxm = 5e5 + 10;
const int mod = 104857601;
int n, k;
int a[maxn];
int main()
{
    scanf("%d %d", &n, &k);
    for(int i = 1 ; i <= n ; ++ i) scanf("%d", &a[i]);
    sort(a + 1, a + 1 + n);
    cout << a[k];
    return 0;
}

牛客小白月赛14(部分题解)_第4张图片

#include
using namespace std;
int n,s;double e=(1+sqrt(5))/2;
int main(){
    cin>>n;
    for(int q=1;q*q<=n;q++)
        for(int p=q;p<=q*e;p++)
            if(__gcd(p,q)==1) s+=n/p/p;
    cout<<s;
}

牛客小白月赛14(部分题解)_第5张图片

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
#define endl '\n'
const double pi = acos(-1);
const int maxn = 2e7 + 10;
const int maxm = 5e5 + 10;
const int mod = 104857601;
int n, m;
int a[maxn], b[maxn];
int main()
{
    scanf("%d %d %d", &n, &a[1], &m);
    for(int i = 1 ; i <= n ; ++ i) b[i] += a[1];
    for(int i = 2 ; i <= n ; ++ i){
        a[i] = (a[i-1] + 7*i) % m;
        for(int j = i ; j <= n ; j += i){
            b[j] += a[i];
        }
    }
    ll ans = 0;
    for(int i = 1 ; i <= n ; ++ i) ans ^= b[i];
    cout << ans;
    return 0;
}

牛客小白月赛14(部分题解)_第6张图片

#include
using namespace std;
#define ll long long
const int maxn = 1e7 + 10;
const ll mod = 1e9 + 7;
int n, k, cnt;
bool prime[maxn];
ll Prime[maxn], p[maxn];
ll ksm(ll a, ll b){
    ll ans = 1, base = a % mod;
    while(b){
        if(b & 1) ans = (ans * base) % mod;
            base = (base * base) % mod;
        b >>= 1;
    }
    return ans % mod;
}
void make(){
    for(int i=0;i<maxn;i++)
        p[i]=ksm(i,k);
}
int main()
{

    scanf("%d %d", &n, &k);
    make();
    ll ans = 0;
    for(int i = 1 ; i <= n ; ++ i){
        ans = (ans + (n/i)*p[i]) % mod;
    }
    cout << (ans + mod) % mod;
    return 0;
}


你可能感兴趣的:(牛客小白月赛14(部分题解))