codeforces 827E

(1)s_{i}=V,s_{i+d}=K。考虑翻转字符串s_i=V,t_{n+1-(i+d)}=K。对应a_i=1,b_{n+1-(i+d)}=1。做一下卷积,对应系数不为0则为不合法。

(2)s_{i-d}=K,s_{i}=V。考虑翻转字符串s_i=V,t_{n+1-(i-d)}=K。对应a_i=1,b_{n+1-(i-d)}=1。做一下卷积,对应系数不为0则为不合法。

注意:如果d不能作为循环节的周期,那么d的所有约数都不能作为周期。类似于埃氏筛搞一下就好了。

#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define sz(x)  (int)x.size()
#define cl(x)  x.clear()
#define all(x)  x.begin() , x.end()
#define rep(i , x , n)  for(int i = x ; i <= n ; i ++)
#define per(i , n , x)  for(int i = n ; i >= x ; i --)
#define mem0(x)  memset(x , 0 , sizeof(x))
#define mem_1(x)  memset(x , -1 , sizeof(x))
#define mem_inf(x)  memset(x , 0x3f , sizeof(x))
#define debug(x)  cerr << #x << " = " << x << '\n'
#define ddebug(x , y)  cerr << #x << " = " << x << "   " << #y << " = " << y << '\n'
#define ios std::ios::sync_with_stdio(false) , cin.tie(0)
using namespace std ;
typedef long long ll ;
typedef long double ld ;
typedef pair<int , int> pii ;
typedef pair<ll , ll> pll ;
typedef double db ;
const int mod = 998244353 ;
const int maxn = 5e5 + 10 ;
const int inf = 0x3f3f3f3f ;
const double eps = 1e-6 ; 
struct NTT
{
    int n , m ;
    ll a[maxn << 2] , b[maxn << 2] ;
    ll up , l ;
    ll pos[maxn << 2] ;
    ll powmod(ll a , ll b)
    {
        ll ans = 1 ;
        while(b)
        {
            if(b & 1)  ans = ans * a % mod ;
            a = a * a % mod ;
            b >>= 1 ;
        }
        return ans ;
    }
    void init(int n , int m) 
    {
        up = 1 , l = 0 ;
        while(up < (n + m))  up <<= 1 , l ++ ;
        rep(i , 0 , up - 1)  pos[i] = (pos[i >> 1] >> 1) | ((i & 1) << (l - 1)) , a[i] = b[i] = 0 ;
    }
    void solve(ll *a , int mode)
    {
        rep(i , 0 , up - 1)  if(i < pos[i])  swap(a[i] , a[pos[i]]) ;
        for(int i = 1 ; i < up ; i <<= 1)
        {
            ll gn = powmod(3 , (mod - 1) / (i << 1)) ; 
            if(mode == -1)  gn = powmod(gn , mod - 2) ;
            for(int j = 0 ; j < up ; j += (i << 1))
            {
                ll g = 1 ;
                for(int k = 0 ; k < i ; k ++ , g = g * gn % mod)
                {
                    ll x = a[j + k] , y = g * a[j + k + i] % mod ;
                    a[j + k] = (x + y) % mod , a[j + k + i] = (x - y + mod) % mod ;
                }
            }
        }
        if(mode == -1) 
        {
            ll invup = powmod(up , mod - 2) ;
            rep(i , 0 , up - 1)  a[i] = a[i] * invup % mod ;
        }
    }
} ntt ; 
int main()
{
    ios ; 
    int T ;
    cin >> T ;
    while(T --)
    {
        int n ;
        cin >> n ;
        string s ;
        cin >> s ;
        ntt.init(n + 1 , n + 1) ;
        vector<bool> vis(n + 1 , false) ;
        for(int i = 1 ; i <= n ; i ++)  
            if(s[i - 1] == 'V')  ntt.a[i] = 1 ;
            else if(s[i - 1] == 'K')  ntt.b[n + 1 - i] = 1 ;
        //for(int i = 0 ; i <= n ; i ++)  cout << ntt.a[i] << " \n"[i == n] ;
        //for(int i = 0 ; i <= n ; i ++)  cout << ntt.b[i] << " \n"[i == n] ;
        ntt.solve(ntt.a , 1) ;
        ntt.solve(ntt.b , 1) ;
        rep(i , 0 , ntt.up - 1)  ntt.a[i] *= ntt.b[i] , ntt.a[i] %= mod ;
        ntt.solve(ntt.a , -1) ;
        //for(int i = 0 ; i <= n ; i ++)  cout << ntt.a[i] << " \n"[i == n] ;
        for(int i = 2 ; i <= n ; i ++)  if(ntt.a[i] >= 1)  vis[n + 1 - i] = true ;
        for(int i = n + 2 ; i <= 2 * n ; i ++)  if(ntt.a[i] >= 1)  vis[i - (n + 1)] = true ;
        for(int i = 1 ; i <= n ; i ++)
            for(int j = i + i ; j <= n ; j += i)
                vis[i] = vis[i] | vis[j] ;
        cout << count(vis.begin() + 1 , vis.end() , false) << '\n' ;
        for(int i = 1 ; i <= n ; i ++)  if(!vis[i])  cout << i << ' ' ;
        cout << '\n' ;
    }
    return 0 ;
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值