zoukankan      html  css  js  c++  java
  • 数论+乱搞——cf181B

    /*
    2-type B|D^k
    3-type B|D-1
    11-type B|D+1 
    6-type B质因子分解, 
    7-type 其他情况 
     
    3-type:
        (a*(D^4-1)+b*(D^3-1)+...+d*(D-1)) % B = 0
        B|(D-1)  
    11-type:
        (a*(D^4-1)+b*(D^3+1)+c*(D^2-1)+d*(D^1+1)) % B=0
        B|(D^k+(-1)^k)
        k为奇数时,D^k-1因式分解后必然有B|(D+1) 
        k为偶数时,(D+1)(D^(k-1)-D^(k-2)+D^(k-3)...+1),也必有B|(D+1)
        且对于任意的k,(D^k+(-1)^k)只有(D+1)这个公因子
    
    */
    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long 
    
    int prime[200],vis[200],m;
    void init(){
        for(int i=2;i<=100;i++){
            if(!vis[i])prime[++m]=i;
            for(int j=i;j<=100;j+=i)
                vis[j]=1;
        }
    }
    
    ll D,B;//D进制下,除数是B 
    
    int k;
    int calc(ll B){
        if((D-1)%B==0)return 3;
        if((D+1)%B==0)return 11;
        ll tmp=D;
        k=0;
        for(;tmp<=1e16;tmp*=D){//2^7
            ++k;
            if(tmp%B==0)return 2;
        }
        
        return -1;
    }
    
    int main(){
        init();
        cin>>D>>B;
        int res=calc(B); 
        if(res!=-1){
            if(res==2){
                cout<<"2-type"<<'
    ';
                cout<<k<<'
    ';
                return 0;
            }
            else if(res==3){
                cout<<"3-type"<<'
    ';
                return 0;
            }
            else if(res==11){
                cout<<"11-type"<<'
    ';
                return 0;
            }
            return 0;
        }
        
        for(int i=1;i<=m;i++)
            if(B%prime[i]==0){//每个质因子都要符合要求 
                ll tmp=1;
                while(B%prime[i]==0)
                    B/=prime[i],tmp*=prime[i];
                int res=calc(tmp);
                if(res==-1){
                    cout<<"7-type"<<'
    ';
                    return 0;
                }
            }
    
        cout<<"6-type"<<'
    ';
    } 
  • 相关阅读:
    自考毕业答辩总结
    【项目经验】navicat工具 SQLServer数据库迁移MySQL
    【项目经验】EasyUI Tree
    Django框架基础(一)
    前端相关内容补充
    web框架前戏---web框架的本质
    web框架前戏---基础简介及Django安装配置
    sqlAchemy前戏
    mysql基础(五)之pymysql
    mysql基础(四)之索引
  • 原文地址:https://www.cnblogs.com/zsben991126/p/11746118.html
Copyright © 2011-2022 走看看