codeforces goodbye 2018 C. New Year and the Sphere Transmission D. New Year and the Permutation Concatenation

这两题都是打表找的规律,C题发现具有相同最大因子的数字所走的点是一样的,D题发现排列数和开头有几个相同的数字有关,所以用排列数公式算出有几个这样的开头再乘上这种开头的种类数就可以了

C题

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll res[2010];
int tot;
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i*i<=n;i++)
    {
        if(n%i==0)
        {
            ll num=n/i;
            res[++tot]=num+1LL*(num-1)*num/2*i;
            if(i*i==n)
               continue;
            ll tmp=n/i;
            num=n/tmp;
            res[++tot]=num+1LL*(num-1)*num/2*tmp;
        }
    }
    sort(res+1,res+tot+1);
    for(int i=1;i<=tot;i++)
    {
        if(res[i]!=res[i-1])
          printf("%lld ",res[i]);
    }
    printf("\n");
}

D题

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll A[1000010];
const ll MOD=998244353;
int main()
{
    int n;
    scanf("%d",&n);
    A[1]=1;
    for(int i=2;i<=n;i++)
    {
        A[i]=A[i-1]*i%MOD;
    }
    ll res=A[n];
    ll now=n;
    for(int i=1;i<=n-2;i++)
    {
        res+=(A[n-i]-1)*now;
        res%=MOD;
        now*=(n-i);
        now%=MOD;
    }
    printf("%lld\n",res);
}

猜你喜欢

转载自www.cnblogs.com/lishengkangshidatiancai/p/10205339.html