题意

给出一个长为200的01序列,判断是否在前1e9个莫比乌斯*值中。(这里的莫比乌斯值加了绝对值)

分析

意到因为4的倍数一定是0,9的倍数一定是0……169的倍数一定是0。那么我们可以对4,9,25,49,121,169这6个200以内这质数平方进行考虑。

我们可以枚举起点位置 $x$ 对这6个数的模数,然后用CRT求出 $x$。对每个起点位置,暴力对比即可。不可能存在所有的mu值,只能单个求。

由于0的个数介于65~95,所以符合条件的起点位置并不多,因此不会超时。

#include <bits/stdc++.h>
using namespace std; typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll up = 1e9;
const int N = 5e4 + ; int prime[N];
bool notprime[N];
void getprime()
{
for (int i = ; i < N; i++) {
if(!notprime[i]) prime[++prime[]] = i;
for (int j = ; j <= prime[] && i * prime[j] < N; j++)
{
notprime[i * prime[j]] = ;
if(i%prime[j]==) break;
}
}
} int mu(int x) { //求单个mu值
for (int i = ; i <= prime[] && prime[i] * prime[i] <= x; i++) {
if(x%(prime[i]*prime[i]) == ) return ;
if(x%prime[i] == ) x/=prime[i];
}
return ;
} ll exgcd(ll a,ll b,ll &x, ll &y) {
ll g = a;
if(b==) x=,y=; else g=exgcd(b,a%b,y,x),y-=x*(a/b);
return g;
} ll inv(ll a,ll m) {
ll x, y;
ll d = exgcd(a, m, x, y);
return (d == ) ? (x % m + m) % m : -;
} int ti[], m[] = {, , , , , }, a[];
int M; void CRT() {
M = ;
for(int i = ; i < ; i ++) M = M*m[i];
for(int i = ; i < ; i++) {
int Mi = M/m[i];
ti[i] = 1LL*inv(Mi, m[i])*Mi%M;
}
} string s,t; int check(int v, int r) {
while(v < ) {
if(s[v] == '') return ;
v += r;
}
return ;
} int ok(int x) {
for (int i = ; i < ; i++)
if(mu(i+x) != s[i]-'') return ;
return ;
} int ans = inf; void dfs(int x) {
if(x == ) {
int v = ;
for(int i = ; i < ; i++) v = (v + 1LL*ti[i]*a[i]%M)%M; //v为CRT的值
if(v == ) v = M;
while(v+ <= up && v < ans) {
if(ok(v)) ans = v;
v = v + M;
}
return;
}
for(int i = ; i < m[x]; i++) { //枚举余数a[i]
if(check(i, m[x])) {
a[x] = ( m[x] - i );
dfs(x+);
}
}
} int main(){
getprime();
CRT();
for(int i = ; i < ; i++) {cin >> t, s = s + t;}
int num = ;
for(int i = ; i < s.size(); i++)
if(s[i] == '') num++;
if(num < || num > ) //0的个数在一个范围内
cout << - << endl;
else {
dfs();
if(ans == inf)
cout << - << endl;
else
cout << ans << endl;
}
return ;
}

参考链接:

1. https://blog.csdn.net/BUAA_Alchemist/article/details/86652706

2. https://blog.csdn.net/a1214034447/article/details/86373308

3. https://ac.nowcoder.com/acm/contest/view-submission?submissionId=40622831

Gym - 102056C(2018EC final) -Heretical … Möbius ——CRT的更多相关文章

  1. CF388C&&2018EC Final D题——博弈&&水题

    一下两个题目都是按堆取石子,轮流取,每个人都贪心的取即可,感觉都不像博弈. CF388C 有n排石子,每排有若干堆.Ciel可以选择一排,拿走这一排的第一堆石子.Jiro可以选择一排,拿走这一排的最后 ...

  2. 我又造了个轮子:GrpcGateway

    我个人对GRPC是比较感兴趣的,最近在玩通过前端调用GRPC.通过前端调用GRPC业界有两种方式:GRPC Web和GRPC JSON转码. GRPC Web 通过JS或者Blazor WASM调用G ...

  3. Gym 102056I - Misunderstood … Missing - [DP][The 2018 ICPC Asia-East Continent Final Problem I]

    题目链接:https://codeforces.com/gym/102056/problem/I Warm sunshine, cool wind and a fine day, while the ...

  4. Gym 102056L - Eventual … Journey - [分类讨论][The 2018 ICPC Asia-East Continent Final Problem L]

    题目链接:https://codeforces.com/gym/102056/problem/L LCR is really an incredible being. Thinking so, sit ...

  5. 2016-2017 National Taiwan University World Final Team Selection Contest (Codeforces Gym) 部分题解

      D 考虑每个点被删除时其他点对它的贡献,然后发现要求出距离为1~k的点对有多少个. 树分治+FFT.分治时把所有点放一起做一遍FFT,然后减去把每棵子树单独做FFT求出来的值. 复杂度$nlog^ ...

  6. Codeforces Gym 101775D Mr. Panda and Geometric Sequence(2017-2018 ACM-ICPC Asia East Continent League Final,D题,枚举剪枝)

    题目链接  ECL-Final 2017 Problem D 题意  给定$2*10^{5}$组询问,每个询问求$l$到$r$之间有多少个符合条件的数 如果一个数小于等于$10^{15}$, 并且能被 ...

  7. Gym 100917J---Judgement(01背包+bitset)

    题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...

  8. Codeforces gym 100685 F. Flood bfs

    F. FloodTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/F Desc ...

  9. Gym 100952I&&2015 HIAST Collegiate Programming Contest I. Mancala【模拟】

    I. Mancala time limit per test:3 seconds memory limit per test:256 megabytes input:standard input ou ...

随机推荐

  1. 关于交叉编译Nodejs的坑

    前言 交叉编译Nodejs到其他平台上的时候,遇到了2个坑,网上极少有人提及,花了整个晚上才解决,在此记录下. 我的编译目标环境为: 龙芯3A 编译脚本 cd 代码目录 export PREFIX=/ ...

  2. SWIG 3 中文手册——5. SWIG 基础知识

    目录 5 SWIG 基础知识 5.1 运行 SWIG 5.1.1 输入格式 5.1.2 SWIG 输出 5.1.3 注释 5.1.4 C 预处理器 5.1.5 SWIG 指令 5.1.6 解析限制 5 ...

  3. ant-design-pro引用css

    ant-design-pro中默认只能引用less文件,引用了css文件也是无效的.所以需要在配置文件config.js中找到  cssLoaderOptions,在 getLocalIdent中加入 ...

  4. [转帖]PostgreSQL的时间/日期函数使用

    PostgreSQL的时间/日期函数使用 https://www.cnblogs.com/mchina/archive/2013/04/15/3010418.html 这个博客的 文章目录比上一个好十 ...

  5. [IOT] - 在树莓派的 Raspbian 系统中安装 .Net Core 3.0 运行环境

    之前在 Docker 中配置过 .Net Core 运行环境,地址:[IOT] - Raspberry Pi 4 Model B 系统初始化,Docker CE + .Net Core 开发环境配置 ...

  6. Failed to instantiate [org.elasticsearch.client.transport.TransportClient]

    Springboot 集成 ElasticSearch,springboot报错如下: Error starting ApplicationContext. To display the auto-c ...

  7. 【spring boot】加载同名Bean解决方法

    原文地址:https://blog.csdn.net/liuyueyi25/article/details/83280239 @SpringBootApplication @ComponentScan ...

  8. Java虚拟机内存区域详解

    JVM 运行时的数据区域 首先获取一个直观的认识: 总共也就这么 5 个区(直接内存不属于 JVM 运行时数据区的一部分),除了程序计数器其他的地方都有可能出现 OOM (OutOfMemoryErr ...

  9. 02、JDBC查询

    ① 向数据库发送SQL查询语句 首先使用Statement声明一个SQL语句对象,然后让已创建的连接对象con调用方法createStatement()创建SQL语句对象. Statement sql ...

  10. 【转载】C#的ArrayList使用IndexOf方法查找第一个符合条件的元素位置

    在C#的编程开发中,ArrayList集合是一个常用的非泛型类集合,在ArrayList集合中如果需要查找第一个符合条件的元素所在的位置,可以使用ArrayList集合的IndexOf方法,Index ...