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

这两题都是打表找的规律,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);
}

 

转载于:https://www.cnblogs.com/lishengkangshidatiancai/p/10205339.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值