0
点赞
收藏
分享

微信扫一扫

AtCoder Regular Contest 067

栖桐 2023-02-08 阅读 98


C - Factors of Factorial

Time Limit: 2 sec / Memory Limit: 256 MB

Score : 300300 points

Problem Statement

You are given an integer NN. Find the number of the positive divisors of N!N!, modulo 109+7109+7.

Constraints

  • 1≤N≤1031≤N≤103

Input

The input is given from Standard Input in the following format:

NN

Output

Print the number of the positive divisors of N!N!, modulo 109+7109+7.

Sample Input 1 Copy

Copy

3

Sample Output 1 Copy

Copy

4

There are four divisors of 3!3! =6=6: 11, 22, 33 and 66. Thus, the output should be 44.

Sample Input 2 Copy

Copy

6

Sample Output 2 Copy

Copy

30

Sample Input 3 Copy

Copy

1000

Sample Output 3 Copy

Copy

972926972

题意:

求n!的因子个数。

分析:

唯一分解定理推论

AtCoder Regular Contest 067_#define

暴力枚举1~n的进行求指数即可

#include <bits/stdc++.h>
using namespace std;
#define ll long long

const int mod = 1e9+7;


int p[1005], c[1005];
ll cnt;//因子个数
const ll N = 1e6+10;
ll prime[N] = {0},num_prime = 0; //prime存放着小于N的素数
int isNotPrime[N] = {1, 1}; // isNotPrime[i]如果i不是素数,则为1
int Prime()
{
for(ll i = 2 ; i < N ; i ++)
{
if(! isNotPrime[i])
prime[num_prime ++]=i;
//无论是否为素数都会下来
for(ll j = 0 ; j < num_prime && i * prime[j] < N ; j ++)
{
isNotPrime[i * prime[j]] = 1;
if( !(i % prime[j] ) ) //遇到i最小的素数因子
//关键处1
break;
}
}
return 0;
}
///与素数筛选一起用的质数分解
///将x分解为式n=(p1^α1)*(p2^α2)*(p3^α3)* ....... *(pk^αk)
///数组p和c求解保存底数p1或者指数α1
set<int> sett;
void Dec(ll x)
{
cnt = 0;
for(int i=0; prime[i]*prime[i]<=x&&i<num_prime; i++)
{
if(x%prime[i]==0)
{
int num=0;
while(x%prime[i]==0)
{
num++;
x /= prime[i];
}
p[cnt]=prime[i];
sett.insert(prime[i]);
c[prime[i]]+=num;
}
if(x==1) break;
}
if(x > 1) {
p[cnt]=x;
sett.insert(x);
c[x]+=1;
}

}


int main()
{
Prime();
ll n;
scanf("%lld",&n);
for(int i=2;i<=n;i++)
Dec(i);
ll ans=1;
set<int>::iterator it;
for(it=sett.begin();it!=sett.end();it++)
{
ans=(ans%mod*(c[*it]+1)%mod)%mod;
}
cout<<ans<<endl;
return 0;
}

 

题意:

有N个城市。城市坐标按从西到东递增,x[i]。

移动的方法有以下两种:

一,在直线上按东西方向平移,每移动一个单位距离疲劳值加A

二,直接瞬移到某个坐标,并且疲劳值加B

请使用以上两种方式直到去完其他所有的城市,并求出最小的疲劳值。

分析:

简单贪心

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 100005;
const int mod = 1e9+7;
ll x[N];
int main()
{
ll n,a,b;
scanf("%lld%lld%lld",&n,&a,&b);
for(int i=1;i<=n;i++)
{
scanf("%lld",&x[i]);
}
ll ans=0;
for(int i=2;i<=n;i++)
{
ll t1=(x[i]-x[i-1])*a;
ll t2=b;
if(t1>t2)
ans+=t2;
else
ans+=t1;
}
cout<<ans<<endl;
return 0;
}

 

举报

相关推荐

0 条评论