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;
    }
  • 相关阅读:
    Js 作用域链
    JS 上下文模式
    javascript
    HTTP概念进阶
    JavaScript运行机制详解
    浅谈循环中setTimeout执行顺序问题
    Js 运行机制 (重点!!)
    javascript
    jQuery 知识点总结
    Educational Codeforces Round 87 (Rated for Div. 2)
  • 原文地址:https://www.cnblogs.com/love-fromAtoZ/p/8954859.html
Copyright © 2011-2022 走看看