首页 > 其他分享 >Educational Codeforces Round 138 (Rated for Div. 2)

Educational Codeforces Round 138 (Rated for Div. 2)

时间:2022-10-21 10:55:37浏览次数:74  
标签:Educational Rated int Codeforces long Div 138 define

比赛链接

Educational Codeforces Round 138 (Rated for Div. 2)

D. Counting Arrays

解题思路

容斥原理

显然 \([1,1,\dots,1]\) 是一组方案,直接求不好求解,考虑反面,对于 \([2,3,\dots,n]\) 的数 \(x\),如果 \(gcd(x,i)=1\) 则显然构造一组解,则要求 \(x\) 与 \(i\) 前面所有的素数都不互质,求出前面所有素数乘积 \(mul\),这样的数共有 \(m/mul\) 个

中间有部分过程爆long long有点难受

  • 时间复杂度:\(O(nlogn)\)

代码

// Problem: D. Counting Arrays
// Contest: Codeforces - Educational Codeforces Round 138 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1749/problem/D
// Memory Limit: 512 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

// %%%Skyqwq
#include <bits/stdc++.h>
 
#define int long long
#define help {cin.tie(NULL); cout.tie(NULL);}
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
using namespace std;
 
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
 
template <typename T> bool chkMax(T &x, T y) { return (y > x) ? x = y, 1 : 0; }
template <typename T> bool chkMin(T &x, T y) { return (y < x) ? x = y, 1 : 0; }
 
template <typename T> void inline read(T &x) {
    int f = 1; x = 0; char s = getchar();
    while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
    while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
    x *= f;
}

const int mod=998244353;
int ksm(int a,int b,int p)
{
	int res=1%p;
	while(b)
	{
		if(b&1)res=(__int128)res*a%p;
		a=(__int128)a*a%p;
		b>>=1;
	}
	return res;
}
bool is(int x)
{
	for(int i=2;i<=x/i;i++)
		if(x%i==0)return false;
	return true;
}
signed main()
{
    int n,m,res=0,a=1,t=1,ot=0;
    cin>>n>>m;
    for(int i=1;i<=n;i++)res=(res+ksm(m,i,mod))%mod;
    for(int i=1;i<=n;i++)
    {
    	if(is(i))
    	{
    		if((__int128)a*i<=m)a*=i;
    		else
    			break;
    	}
    	t=(__int128)t*(m/a)%mod;
    	ot=(ot+t)%mod;
    }
    res-=ot;
    cout<<(res%mod+mod)%mod;
    return 0;
}

标签:Educational,Rated,int,Codeforces,long,Div,138,define
From: https://www.cnblogs.com/zyyun/p/16812722.html

相关文章

  • 论文解读(FedPCL)《Federated Learning from Pre-Trained Models: A Contrastive Learni
    论文信息论文标题:FederatedLearningfromPre-TrainedModels:AContrastiveLearningApproach论文作者:YueTan,GuodongLong,JieMa,LuLiu,TianyiZhou,JingJ......
  • Educational Codeforces Round 92 B
    B.ArrayWalk考虑dpdp[i][j]表示前i步我们撤销了j次状态转移:dp[i][j]=max{dp[i-1][j-1]+a[(i-1)-(j-1)2-1]}//我们撤销一位dp[i][j]=max{dp[i-1][j]+a[(i-1)-j2+1]}......
  • Codeforces Global Round 23-C
    C题目链接:https://codeforces.com/contest/1746/problem/C此题着实不难,就是看你自己能不能想到那种构造的方法。自己做的时候没有很好的思路,所以参考了官方的解析()。个人......
  • Educational Codeforces Round 103 C
    C.LongestSimpleCycle显然针对ab相等的话那我们就不能再往前走了所以我们考虑分为几个层我们考虑如何求出一个层的最长环我们观察这个红色的环显然我们正着做反......
  • Codeforces Round #202 (Div. 1) A. Mafia 推公式 + 二分答案
    ​​http://codeforces.com/problemset/problem/348/A​​A.MafiatimelimitpertestmemorylimitpertestinputoutputOnedaynfriendsgatheredtogethertoplay"Ma......
  • Codeforces Round #699 C
    C.FencePainting显然对于我们不同的就直接修改但是我们应该贪心的叫更后面来的人来修改这样前面的人怎么造都无所谓了for(inti=1;i<=n;i++){if(a[i]!=b[i]......
  • CodeCraft-21 and Codeforces Round #711 C
    C.PlanarReflections考虑dpdp[i][j]表示i能量的在第j层的cnt显然我们会分裂成左右两部分dp[i][j]=dp[i-1][n-j]+dp[i][j-1]我们为了不讨论方向问题直接记忆化搜索......
  • Educational Codeforces Round 137 (Rated for Div. 2) - D. Problem with Random Tes
    期望+暴力[Problem-D-Codeforces](https://codeforces.com/contest/1743/problem/E)题意给出一个长度为\(n\;(1<=n<=10^6)\)的字符串\(s\),选取两个\(s\)的......
  • Educational Codeforces Round 137 (Rated for Div. 2) - E. FTL
    DPProblem-E-Codeforces题意有个BOSS有\(H\;(1<=H<=5000)\)血量,\(s\)点防御有两种武器可用攻击BOSS,伤害分别为\(p_1,p_2\;(s<min(p_1,p_2)<=5000)\),冷却......
  • Codeforces Round #712 A
    A.BalancetheBits显然对于一个字符串s我们每一对0之间必须是()一个合法的括号才行)(也可以显然是等价的因为你a拿前者b就会拿后者所以这就要求了我们0的个数必须是偶......