66分求助
查看原帖
66分求助
1110672
XY_wind楼主2024/6/17 19:41

麻烦大佬看看哪里错了T-T
真找不到错误了……

#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,k,ans,t;
int a[5000010];
bool aaa(int x){
	if(x==1) return 0;
	for(ll l=2;l<=sqrt(x);++l){
		if(x%l==0) return 0;
	}
	return 1;
}
void dfs(int x,int y,int z){
	z++;
	for(ll j=y;j<=n;++j){
		t+=a[j];
		if(z==x){ 
			if(aaa(t)==1){
				t-=a[j];
				ans++;
			}
		}
		else dfs(x,y+j,z);
	}
	z--;
	return;
}
int main(){
	cin>>n>>k;
	for(ll i=1;i<=n;++i) cin>>a[i];
	for(ll i=1;i<=n;++i){
		t=0;
		t+=a[i];
		dfs(k,i+1,1);
	}
	cout<<ans;
	return 0;
}
2024/6/17 19:41
加载中...