zoukankan      html  css  js  c++  java
  • int型素数拆分

    #include <iostream>
    #include <cstdio>
    #include <cmath>
    using namespace std;
     
    int ans = 0;
    int flag = 0;
    int t1 = 0;
    int t2 = 0;
    void primeFactor(int n){
        while(n % 2 == 0){
            //printf("2 ");
            ans = 1;
            n /= 2;
            t1 ++;
            flag = 1;
        }
        for(int i = 3; i <= sqrt(n); i += 2){
            int t = n;
            while(n % i == 0){
                //printf("%d ", i);
                n /= i;
                if(flag == 0){
                    t1 ++;
                }
                else{
                    t2 ++;
                }
            }
            if(t1 != 0){
                flag = 1;
            }
            if(t != n){
                ans ++;
            }
        }
        if(n > 2){
            ans ++;
            //printf("%d ", n);
            if(flag == 0){t1 ++;}
            else{t2 ++;}
        }
    }
    int main(){
        int n,T;
        char in[100];
        scanf("%d",&T);
        while(T --){
            scanf("%d%s",&n,in);
            flag = 0;t1 = 0;t2 = 0;
            ans = 0;
            primeFactor(n);
            //printf(" %d ",ans);
            //printf("%d %d ",t1,t2);
            if(ans >= 3){printf("tie ");}
            else{
                if(ans == 1){
                    if(t1 % 2 == 0){
                        if(in[0] == 'A'){printf("Bob ");}
                        else{printf("Alice ");}
                    }
                    else{
                        if(in[0] == 'B'){printf("Bob ");}
                        else{printf("Alice ");}
                    }
                }
                else if(ans == 2){
                    if(t1 == t2){
                        if(in[0] == 'A'){printf("Bob ");}
                        else{printf("Alice ");}
                    }
                    else if(max(t1,t2) - min(t1,t2) == 1){
                        if(in[0] == 'B'){printf("Bob ");}
                        else{printf("Alice ");}
                    }
                    else if(max(t1,t2) - min(t1,t2) > 1){
                        printf("tie ");
                    }
                }
            }
        }
     
        return 0;
    }
  • 相关阅读:
    scikit-learn算法选择路径图
    mac 添加new file.md
    mac-VBox-Centos6.6安装增强功能
    VirtualBox中安装CentOS使得在ssh和外网都能正常链接
    vboxnetctl: no such file or directory
    mac vim 配色
    埃森哲杯第十六届上海大学程序设计联赛春季赛暨上海高校金马五校赛 B合约数
    codeforces 965E Trie+multiset
    bzoj 4337 树的同构
    codeforces 963B Destruction of a Tree
  • 原文地址:https://www.cnblogs.com/love-fromAtoZ/p/8954859.html
Copyright © 2011-2022 走看看