当前位置:网站首页>Codeforces Round #716 (Div. 2)
Codeforces Round #716 (Div. 2)
2022-06-27 19:14:00 【我的故事用酒换】
2021.4.19
A
题意:给你n个数的序列,问你是否存在子序列的乘积不是一个平方数
题解:判断n个数的序列是否都是完全平方数
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
int n,x,t;
cin>>t;
while(t--){
cin>>n;
int flag=0;
for(int i=0;i<n;i++)
{
cin>>x;
int k=(int)sqrt(x);
if(k*k!=x)
flag=1;
}
if(flag)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
B
题意:输入两个数n和k,要求构造一个含n个数的序列,且选择的n个数需要从0~
中去选择,要求所有元素按位与为0且所有元素和最大,求可以构造的方案数。
题解:序列需从0~
中选择,所以可以看成每个数都可以化成长度为k的二进制数,要求所有元素按位与为0,k位的二进制每一位都要有一个0,这k个0是从n个数中贡献,要求和最大,所以每一位有且只有一个0,其他同位的都要为1,那么每一个0都可以放在n个数的对应位上,每一个0有n个选择,总共有k个0,答案就是
%1e9+7。
#include <cstdio>
#include <iostream>
#include <algorithm>
#define ll long long
#define mod 1000000007
using namespace std;
ll qpow(ll a,ll b)
{
ll res=1;
while(b)
{
if(b%2)
res=res*a%mod;
a=a*a%mod;
b/=2;
}
return res;
}
int main()
{
ll t,n,k;
cin>>t;
while(t--)
{
cin>>n>>k;
cout<<qpow(n,k)%mod<<endl;
}
return 0;
}
C
题意:输入一个数n,从 [1,2,…,n−1]选出长度最长的序列,使得序列的积取余n为1
题解:
裴属定理:对于非负整数a,b,存在x,y使得ax+by=gcd(a,b),也就是说ax+by能构成的最小正整数就是gcd(a,b),注意(a,b不同时为0)
ax+by=c有解当且仅当c%gcd(a,b)==0,如果gcd(a,b)>1那么c一定大于1,所以gcd(k,n)>1,
,所以要求序列的乘积%n=1,需要从gcd(k,n)=1中去找。
令:
,这时sum
[1,n),要求求余为1,则ans=sum/sum=1,将乘积里的sum去除掉序列的乘积就是1,这样只需要删除一个数就可得到序列乘积取余n为1。
那为什么sum就一定是在s里呢?
假设没有取模,最后得到的结果ans%n=1,所以ans一定是s里的数乘积得到的,而sum是s里的所有数乘积得到的,ans*x=sum,所以这个x一定是s里的数,也就是上述取模后的sum,所以是可以去从s里去除掉的。
#include <cstdio>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
ll gcd(ll a,ll b)
{
return b==0?a:gcd(b,a%b);
}
int main()
{
ll n,ans=1,a[100005],l=0;
cin>>n;
for(int i=1;i<n;i++)
{
if(gcd(i,n)==1){
a[l++]=i;
ans=(ans*i)%n;
}
}
if(ans!=1){
cout<<l-1<<endl;
for(int i=0;i<l;i++)
if(a[i]!=ans)
cout<<a[i]<<' ';
}
else{
cout<<l<<endl;
for(int i=0;i<l;i++)
cout<<a[i]<<' ';
}
cout<<endl;
return 0;
}
边栏推荐
猜你喜欢

SQL必需掌握的100个重要知识点:使用函数处理数据

Release of global Unicorn list in 2021: the full list of 301 Unicorn enterprises in China is coming!

VMware vSphere ESXi 7.0安装教程

Implementation string mystring

展现强劲产品综合实力 ,2022 款林肯飞行家Aviator西南首秀

Data platform scheduling upgrade and transformation | operation practice from Azkaban smooth transition to Apache dolphin scheduler

抖音的兴趣电商已经碰到流量天花板?

释放开源数据库创新力量 | 【甘肃】openGauss Meetup圆满结束

Icml2022 | scalable depth Gaussian Markov random field

mysql使用笔记一
随机推荐
SQL必需掌握的100个重要知识点:检索数据
强制 20 天内开发 APP 后集体被裁,技术负责人怒批:祝“早日倒闭!”
Zhongang Mining: the largest application field of new energy or fluorite
100 important knowledge points that SQL must master: retrieving data
GoLand permanently activated
Is it safe to open an account and buy stocks on the Internet? New to stocks, no guidance
Flutter隐藏AppBar的返回按钮
At 19:00 on Tuesday evening, the 8th live broadcast of battle code Pioneer - how to participate in openharmony's open source contribution in multiple directions
关于企业数字化的展望(38/100)
Love math experiment | phase VI - Financial anti fraud case study
实际工作中用到的shell命令 - sed
抗洪救灾,共克时艰,城联优品驰援英德捐赠爱心物资
于文文、胡夏等明星带你玩转派对 皮皮APP点燃你的夏日
Unity3d button adapts the size according to the text content
DO280OpenShift访问控制--security policy和章节实验
动物养殖生产虚拟仿真教学系统|华锐互动
教程|fNIRS数据处理工具包Homer2下载与安装
Dictionary tree (review)
爱数课实验 | 第八期-新加坡房价预测模型构建
MySQL performance optimization index function, hidden, prefix, hash index usage (2)