B. Integral Array (思维 一点点数学)

42 篇文章 0 订阅
13 篇文章 0 订阅

Problem - B - Codeforces

题意:给你一个数组,判断是否每两个数的向下取整相除的值也在数组中。 

n<=1000000,那么枚举所有的两个数是n^2的,不行;

题目说了所有数小于1000000,那么我们考虑枚举每个数的倍数,假如在倍数范围内有数出现过,那么就说明存在相应的x和y,我们再判一下\left \lfloor x/y \right \rfloor是否也在数组里即可。

有点巧妙。

还有,判倍数内有没有数出现过要用标记数组加前缀和减一下,不然枚举也会寄。

有点妙妙。

/*keep on going and never give up*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define db(x) cerr<<(#x)<<" "<<(x)<<" "<<endl;
#define endl "\n"
#define INF 1e17
#define fast std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const double E = exp(1);
const double PI = acos(-1.0);
const int maxn=2e6+10; 
int n,m,k,a[maxn],b[maxn],s[maxn];
signed main(){
	fast
	int t=1;
	cin>>t;
	while(t--){
		cin>>n>>k;
		for(int i=0;i<=k;i++) b[i]=0;
		for(int i=1;i<=n;i++) cin>>a[i],b[a[i]]=1;
		bool f=1;
		if(!b[1]){
			cout<<"NO\n";continue;
		}
		s[0]=0;
		for(int i=1;i<=k;i++) s[i]=s[i-1]+b[i];
		for(int i=2;i<=k;i++){
			if(!b[i]) continue;
			for(int j=i;j<=k;j+=i){
				if(s[min(j+i-1,k)]-s[j-1])
					if(!b[j/i]) f=0;
			}
		}
		if(f) cout<<"YES\n";
		else cout<<"NO\n";
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值