1635 - Irrelevant Elements

根据递推公式,(指数也可以利用这个公式)    由刘汝佳所言,只需判断二项式展开式的每个项的系数是否是m的倍数即可,由唯一分解定律,只要指数大于m的分解项指数,就可以除尽这一项;    但是要注意,并不是每个项都可以被唯一分解完全的。

#include<bits/stdc++.h>
using namespace std;
int n,m,vis[42000+5],max_cnt,c[100000+6],a[100000+5],prime[100000+5],e[100000+5];
vector<int> primes;
void add_primes() {        //打出素数表。
    int m = sqrt(32000+0.5);
    memset(vis,0,sizeof(vis));
    for(int i=2;i<=m;i++) if(!vis[i])
    for(int j=i*i;j<=32000;j+=i) vis[i] = 1;
    for(int i=2;i<=32000;i++)
        primes.push_back(i);
}
void add_factors(int n) {
    max_cnt=0;
    for(int i=0;i<primes.size();i++){
        if(n%primes[i]==0) prime[max_cnt++]=primes[i];
        while(n%primes[i]==0) {
            n/=primes[i];
            e[max_cnt-1]++;
        }
        if(n==1) break;//提前推出,节省时间。
    }
    if(n>1) { prime[max_cnt]=n; e[max_cnt++]=1; } //必不可少
}
int main() {
    add_primes();
    while(scanf("%d%d",&n,&m)!=EOF) {
        memset(c,0,sizeof(c));
        memset(e,0,sizeof(e));
        add_factors(m);
        n--;
        for(int i=0;i<max_cnt;i++) {
            int max_e=0;   //当前项系数情况。
            for(int k=1;k<=n;k++) {
                int ans = n-k+1;
                while(ans%prime[i]==0) {
                    ans/=prime[i];
                    max_e++;
                }
                ans = k;
                while(ans%prime[i]==0) {
                    ans/=prime[i];
                    max_e--;
                }
                if(max_e<e[i]) c[k] = 1;
            }
        }
        int kase = 0;
        for(int i=1;i<=n;i++){
            if(!c[i]) a[kase++]=i+1;
            }
        if(kase){
            printf("%d\n",kase);
            for(int i=0;i<kase;i++)
                if(!i) printf("%d",a[i]);
                else printf(" %d",a[i]);
            printf("\n");
        }
        else printf("0\n\n");
    }
    return 0;
}


### Self-Attention Mechanism in Neural Networks Introduction and Application In the context of neural networks, self-attention mechanisms allow models to weigh different parts of input data differently when processing sequences or other structured inputs. This approach enhances model performance by focusing on relevant elements while reducing noise from irrelevant ones. The core idea behind self-attention is that it enables each position (or token) within an input sequence to attend over all positions in previous layers, capturing dependencies between tokens regardless of their distance apart[^1]. For instance, in natural language processing tasks such as speech recognition where mel-frequency cepstral coefficients are used as features, this can help capture long-range dependencies more effectively than traditional recurrent architectures like LSTMs which suffer from vanishing gradient problems during training due to sequential nature [^2]. A typical implementation involves three matrices: Query(Q), Key(K), Value(V). These matrices transform embeddings into queries, keys, values respectively before computing dot products followed by softmax normalization across key vectors resulting in attention weights applied onto value vector producing final output representation per word/token after summing weighted contributions together: ```python import torch import torch.nn.functional as F def scaled_dot_product_attention(query, key, value): d_k = query.size(-1) scores = torch.matmul(query, key.transpose(-2,-1)) / math.sqrt(d_k) p_attn = F.softmax(scores,dim=-1) return torch.matmul(p_attn,value) class MultiHeadedAttention(nn.Module): def __init__(self,h,d_model): super().__init__() assert d_model % h ==0 self.d_k=d_model//h self.h=h self.linears=[nn.Linear(d_model,d_model)for _in range(4)] def forward(self,x): nbatches=x.shape[0] query,key,value=[ l(x).view(nbatches,-1,self.h,self.d_k).transpose(1,2) for l,x in zip(self.linears,(query,key,value)) ] x=self.scaled_dot_product_attention(query,key,value) ... ``` This method has been successfully utilized not only in NLP but also various domains including computer vision through transformers architecture variations designed specifically around these principles leading towards state-of-the-art results achieved recently.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值