AtCoder Regular Contest 067

AtCoder Regular Contest 067

C - Factors of Factorial

根据唯一分解定理,$N=\prod_{i=1}^{n}p_i^{a_i}$。

那么$N$的因子个数即为$\prod_{i=1}^{n}(a_i+1)$,因数之和为$\prod_{i=1}^{n}\sum_{k=0}^{a_i}p_i^k$。

有一个结论,$N!=\prod_{i=1}^{n}p_i^{a_i}$,则$a_i=\sum_{k=1}^{\infty}\frac{N}{p_i^k}$。

 1 #include<cstdio>
 2 #include<iostream>
 3 using namespace std;
 4 typedef long long ll;
 5 const int mo = 1e9 + 7;
 6 int isnp[1005], p[1005], num, n;
 7  
 8 ll calc(int n, ll d) {
 9     ll res = 0;
10     for (; n; n /= d) res += n / d;
11     return res;
12 }
13  
14 int main() {
15     scanf("%d", &n);
16     for (int  i = 2; i <= n; ++i) {
17         if (!isnp[i]) p[++num] = i;
18         for (int j = i + i; j <= n; j += i) isnp[j] = 1;
19     } ll ans = 1;
20     for (int i = 1; i <= num && p[i] <= n; ++i) (ans *= (calc(n, p[i]) + 1)) %= mo;
21     printf("%lld\n", ans);
22     return 0;
23 }
View Code

D - Walk and Teleport

很显然,跳到中间是不合适的。所以可以从左往右贪心。

 1 #include<cstdio>
 2 #include<iostream>
 3 using namespace std;
 4 typedef long long ll;
 5 int main() {
 6     ll n, a, b, p, ans = 0, t;
 7     cin >> n >> a >> b >> p;
 8     for (int i = 1; i < n; ++i, p = t) {
 9         cin >> t; ans += min((t - p) * a, b);
10     } cout << ans << endl;
11     return 0;    
12 }
View Code

 

转载于:https://www.cnblogs.com/p0ny/p/8144509.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值