题意

给出一个长为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. oracle 错误 ORA-00020问题解析

    问题描述 [oracle@xiaowu ~]$ sqlplus / as sysdba SQL*Plus: Release Production on Wed Oct :: Copyright (c) ...

  2. 使用ipop共享串口提高工作效率

    串口登录后,点击共享连接 然后在另外一台电脑,使用Telnet打开共享的串口(两台电脑需要可以网络连接) IP地址为对端IP地址,端口号为对端设置的端口号,点击连接即可

  3. R语言学习基础一

    笔者使用Rstudio编写R程序,本文主要总结在编写过程中遇到的一些实际 问题 与学习配套的的code上传到我的github,网址: https://github.com/LIU-HONGYANG/S ...

  4. mongodb集群化

    转自:https://www.cnblogs.com/nulige/p/7613721.html 一.mongodb主从复制配置 主从复制是MongoDB最常用的复制方式,也是一个简单的数据库同步备份 ...

  5. 安装Office 2016 出现 Office 16 Click-to-Run Extensibility Component

    无法安装 64 位版本的 Office,因为在您的 PC 上找到了以下 32 位程序: Office 16 Click-to-Run Extensibility Component 请卸载所有 32 ...

  6. Mysql load data infile 导入数据出现:Data truncated for column

    [1]Mysql load data infile 导入数据出现:Data truncated for column .... 可能原因分析: (1)数据库表对应字段类型长度不够或修改为其他数据类型( ...

  7. mysql判断是否存在数据库和表,进行删除和创建

    1.存在莫数据库,则删除创建一个新库 drop database if exists `tpm_business`; CREATE DATABASE tpm_business DEFAULT CHAR ...

  8. Redis 实战搭建高可用架构

    前言:最近在看关于redis缓存方面的知识,今天就来个 Redis sentinel 高可用架构,实战开始之前,先看看sentinel的概念 什么是redis-sentinel Redis-Senti ...

  9. Blend 触发器

    原文:Blend 触发器 介绍用定义触发器来控制视频 的 开始 暂停 继续 停止 触发器设置 效果

  10. .net 6.0 新特性

    1. 属性初始化 class Person { public string Name { get; set; } public string Sex { get; set; } = "男&q ...