其他分享
首页 > 其他分享> > Complex Market Analysis(1400 math two points)

Complex Market Analysis(1400 math two points)

作者:互联网

 1 /**\
 2 https://codeforces.com/problemset/problem/1609/C
 3 一堆数相乘是质数,其中只有一个是质数,
 4 统计左边的1的个数,右边1的个数,累加即可
 5 \**/
 6 #include <bits/stdc++.h>
 7 using namespace std;
 8 #define fi first
 9 #define se second
10 #define go continue
11 #define int long long
12 #define PII pair<int, int>
13 #define sf(x) scanf("%lld",&x)
14 #define ytz int _; sf(_); while(_--)
15 #define fory(i,a,b) for(int i = a; i <= b; ++i)
16 #define forl(i,a,b) for(int i = a; i >= b; --i)
17 #define debug(a) cout << #a << " = " << a <<endl;
18 const int N = 1e6 + 10;
19 int p[N], cnt;
20 bool st[N];
21 void ola(int n)
22 {
23     st[1] = 1;
24     fory(i, 2, n)
25     {
26         if(!st[i]) p[cnt++] = i;
27         for(int j = 0; p[j] <= n / i; j++)
28         {
29             st[p[j] * i] = true;
30             if(i % p[j] == 0) break;
31         }
32     }
33 }
34 int n, e, a[N];
35 signed main()
36 {
37     ola(1e6);
38     ytz
39     {
40         int ok = 0;
41         sf(n), sf(e);
42         fory(i, 1, n) sf(a[i]);
43         fory(i, 1, n)
44         {
45             if(!st[a[i]])
46             {
47                 int l = 0, r = 0;
48                 for(int j = i - e; j >= 1; j -= e)
49                 {
50                     if(a[j] == 1) l++;
51                     else break;
52                 }
53                 for(int j = i + e; j <= n; j += e)
54                 {
55                     if(a[j] == 1) r++;
56                     else break;
57                 }
58                 ok += r + l *(r + 1);
59             }
60         }
61         cout << ok << "\n";
62     }
63     return 0;
64 }

 

标签:int,质数,个数,two,Analysis,Complex,long,sf,define
来源: https://www.cnblogs.com/-ytz/p/15986366.html