首页 > 其他分享 >Codeforces 1514 C

Codeforces 1514 C

时间:2023-06-08 21:22:05浏览次数:49  
标签:元素 Codeforces 序列 1514 equiv mod

1514 C

题意

给出一个数n,求[1,2,3...n-1]的某个最长子序列,这个子序列的元素乘积模n余1。

思路

这是个思维题,一个数学公式

\[x \equiv 1(mod n) \rightarrow kx\equiv k(mod  kn) \]

所以子序列中的元素与\(n\)互质,累乘结果模\(n\)后如果不是1,那么将序列中等于结果的元素去掉

代码

void solve() 
{
	cin>>n;
	vector<int> a;
	for(int i=1;i<=n;i++) if(__gcd(i,n)==1) a.push_back(i);
	int ans=1;
	for(auto x:a) ans=ans*x%n;
	ans=ans%n;
	if(ans==1) 
	{	
		cout<<a.size()<<endl;
		for(auto x:a) cout<<x<<" ";
		cout<<endl;
	} 
	else 
	{	
		cout<<a.size()-1<<endl;
		for(auto x:a) if(ans!=x) cout<<x<<" ";
		cout<<endl;
	}
}

标签:元素,Codeforces,序列,1514,equiv,mod
From: https://www.cnblogs.com/LIang2003/p/17467720.html

相关文章

  • Codeforces 1515 B
    1515B题意有n只袜子(n为偶数),但左袜子有L只,右袜子有R只,每只袜子的颜色为\(C_i\),可以进行以下操作:换袜子的方向、或者将袜子变色,问进行多少次操作后变成(n/2)对袜子思路很曲折,想了很久后终于想清楚,排除配对的袜子后,对于某类袜子\(i\),剩下\(c\geq2\)(假设剩下的是右边)只,它的配对......
  • CodeForces - 658A Bear and Reverse Radewoosh (模拟)水
    TimeLimit: 2000MS MemoryLimit: 262144KB 64bitIOFormat: %I64d&%I64uCodeForces-658ABearandReverseRadewooshSubmit StatusDescriptionLimakandRadewoosharegoingtocompeteagainsteachotherintheupcomingalgorithmiccontest.Theyareequ......
  • CodeForces - 616B Dinner with Emma (模拟)水
    TimeLimit: 1000MS MemoryLimit: 262144KB 64bitIOFormat: %I64d&%I64uCodeForces-616BDinnerwithEmmaSubmit StatusDescriptionJackdecidestoinviteEmmaoutforadinner.Jackisamodeststudent,hedoesn'twanttogotoanexpensiveres......
  • CodeForces - 659B Qualifying Contest (模拟)水
    TimeLimit: 1000MS MemoryLimit: 262144KB 64bitIOFormat: %I64d&%I64uCodeForces-659BQualifyingContestSubmit StatusDescriptionVerysoonBerlandwillholdaSchoolTeamProgrammingOlympiad.Fromeachofthe m Berlandregionsateamoftwopeo......
  • CodeForces - 670A Holidays (模拟) 水
    TimeLimit: 1000MS MemoryLimit: 262144KB 64bitIOFormat: %I64d&%I64uCodeForces-670AHolidaysSubmit StatusDescriptionOntheplanetMarsayearlastsexactly nInputThefirstlineoftheinputcontainsapositiveinteger n (1 ≤ n ≤ 1 000......
  • Codeforces Round 876 (Div. 2) 题解 A - D
    A.TheGoodArray题目大意给定两个整数\(n\)和\(k\),规定一个\(01\)数列为好的的条件是,对于\(1\simn\)中任意的\(i\),都有:\(a\)的前\(i\)个元素中至少有\(\lceil\frac{i}k\rceil\)个都是\(1\)。\(a\)的后\(i\)个元素中至少有\(\lceil\frac{i}k\rceil\)个都是......
  • codeforces.com/contest/1553/problem/B
    简单字符串哈希题意给一个字符串s和t,问从s的某个位置开始,向右到某个点后再向左,顺序遍历到的字符形成的字符串可否为t。思路数据只有500,\(O(n^3)\)可过,枚举转折点,然后枚举开头和结尾。代码intn,m,k;ullHash[1010],rHash[1010],p[1010],rp[1010],sum;voidsolve(){ ......
  • Codeforces Round 876 (Div. 2) A-D
    比赛地址A.TheGoodArray题意:定义一个数组是good的要求有:从左往右所有的i,前i个数中至少有[i/k]个数是1从右往左所有的i,前i个数中至少有[i/k]个数是1问good数组对于n而言最少需要多少个1Solution先从左往右填1,直到满足第一个条件,然后从右往左填1,直到满足第二个条件voidso......
  • ACM-CodeForces-#685(Div.2)
    A.SubtractorDivide#include<iostream>usingnamespacestd;intmain(){ intT,n; cin>>T; while(T--) { cin>>n; if(n<=3) n--; else n=2+(n&1); cout<<n<<endl; } return0;}B.Non-SubstringSubsequence#in......
  • Codeforces 1566G - Four Vertices(线段树分治)
    交了整整2页,本来想用随机化卡过去的,后来发现我的实现跑得太慢就写正常做法了。首先发现最优答案对应的四个点只可能有以下两种可能:\(a,b\)间有边,\(c,d\)间有边,此时答案是\(a,b\)边权值加\(c,d\)边权值。\(a\)与\(b,c,d\)三个点间都有边,此时答案是三条边权值之和。......