C. Complex Market Analysis

传送门

题意:

给你一个数组和一个e,问有多少对(i,k)能够满足其为质数

(i,k)s[i]*s[i+e]*s[i+2e]*...*s[i+ke]的值

思路:

因为要求某个子区间为质数,那么这其中一定有且只有一个质数。可以提前用筛法预处理1e6 的质数,然后从每一个质数开始往左或者往右不断移动e次,直到当前元素不为1为止,那么结果就是前面的1数量加后面1的数量加两数相乘。



#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define sc_int(x) scanf("%d", &x)
#define sc_ll(x) scanf("%lld", &x)
#define pr_ll(x) printf("%lld", x)
#define pr_ll_n(x) printf("%lld\n", x)
#define pr_int_n(x) printf("%d\n", x)
#define ll long long 
using namespace std;

const int N=3000000+100;
int n ,m,h;
ll s[N],p[N];
bool st[N];int tim;

void solve()
{
	int e;
	cin>>n>>e;
	for(int i =1;i<=n;i++)cin>>s[i];
	ll res=0;
	for(int i =1;i<=n;i++)
	{
		if(!st[s[i]])
		{
			ll a=0,b=0;
			for(int j =i+e;j<=n;j+=e)
			{
				if(s[j]==1)
				{
					res++;
					a++;
				}
				else break;
			}

			for(int j=i-e;j>=1;j-=e)
			{
				if(s[j]==1)
				{
					res++;
					b++;
				}
				else break;
			}
			res+=a*b;
		}
	}
	cout<<res<<endl;
	
	return ;
}


void init()
{
	st[1]=1;
	for(int i =2;i<=2e6;i++)
	{
		if(!st[i])p[++tim]=i;
		for(int j =1;p[j]<=2e6/i;j++)
		{
			st[i*p[j]]=1;
			if(i%p[j]==0)break;
		}
	}
}

int main()
{
	int t;
	init();
	sc_int(t);
	while(t--)solve();
	
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
There are many books on project management and many on embedded systems, but few address the project management of embedded products from concept to production. Project Management of Complex and Embedded Systems: Ensuring Product Integrity and Program Quality uses proven Project Management methods, as well as elements of IEEE embedded software development techniques, to explain how to deliver a reliable complex system to market. Walks managers through the stages of a project’s life cycle so that they can anticipate and prepare for potential problems This volume begins with a general discussion of project management, followed by an examination of the various tools used before a project is underway. The book then delves into the specific project stages: concept, product development, process development, validation of the product and process, and release to production. Finally, post-project stages are explored, including failure reporting, analysis, corrective actions, and product support. The book draws heavily on information from Department of Defense sources as well as systems developed by the Automotive Industry Action Group (AIAG), General Motors, Chrysler, and Ford to standardize the approach to designing and developing new products. These automotive development and production ideas have universal value, particularly the concept of process and design controls. The authors use these systems to explain project management techniques that can assist developers of any embedded system. The methods explored can be adapted toward mechanical development projects as well. The text includes numerous “war stories”offering concrete solutions to problems that might occur in production. Tables and illustrative figures are provided to further clarify the material. Organized sequentially to follow the normal life cycle of a project, this book helps project managers identify challenges before they become problems and resolve those issues that cannot be avoided. About the Author Stoneridge Electronics North America, El Paso, Texas, USA Volvo Trucks, Greensboro, North Carolina, USA

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值