当前位置:网站首页>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;
}
边栏推荐
- 抖音的兴趣电商已经碰到流量天花板?
- Wechat applet based service management system for college party members' Home System applet graduation design, Party members, activists, learning, punch in, forum
- SQL必需掌握的100个重要知识点:创建计算字段
- Kirin V10 installation font
- Can Oracle's CTAs bring constraints and other attributes to the new table?
- Squid proxy server
- CEPH distributed storage
- 展现强劲产品综合实力 ,2022 款林肯飞行家Aviator西南首秀
- 原创翻译 | 机器学习模型服务工具对比:KServe,Seldon Core和BentoML
- 数据平台调度升级改造 | 从Azkaban 平滑过度到Apache DolphinScheduler 的操作实践
猜你喜欢

Here are 12 commonly used function formulas for you. All used ones are good

Best practice: optimizing Postgres query performance (Part 2)

Graduation design of police report convenience service platform based on wechat applet

体验Navicat Premium 16,无限重置试用14天方法(附源码)

Icml2022 | scalable depth Gaussian Markov random field

ICML2022 | 可扩展深度高斯马尔可夫随机场

Focus! Tips for installing fonts on domestic computers

大促场景下,如何做好网关高可用防护

MYSQL 性能优化 index 函数,隐藏,前缀,hash 索引 使用方法(2)

“好声音“连唱10年,星空华文如何唱响港交所?
随机推荐
抖音的兴趣电商已经碰到流量天花板?
Unity3D Button根据文本内容自适应大小
爱数课实验 | 第八期-新加坡房价预测模型构建
Experiment of love number lesson | phase V - emotion judgment of commodity review based on machine learning method
Pycharm common functions - breakpoint debugging
SQL必需掌握的100个重要知识点:检索数据
SQL必需掌握的100个重要知识点:用通配符进行过滤
Love number experiment | Issue 7 - Financial Crisis Analysis Based on random forest
如何将队列里面的内容没秒钟执行一次优先级
GFS distributed file system
1027 Colors in Mars
Share an experience of self positioning + problem solving
UE4 essays: fstring, fname and ftext
MySQL客户端工具推荐,一定想不到最好用巨然是它
动物养殖生产虚拟仿真教学系统|华锐互动
KDD 2022 | graph neural network generalization framework under the paradigm of "pre training, prompting and fine tuning"
Codeforces Round #721 (Div. 2)
Animal breeding production virtual simulation teaching system | Sinovel interactive
Data platform scheduling upgrade and transformation | operation practice from Azkaban smooth transition to Apache dolphin scheduler
308. 2D area and retrieval - variable segment tree / hash