题解 | 小红和小紫的取素因子游戏

小红和小紫的取素因子游戏

https://www.nowcoder.com/practice/6146f391a69547c4804fe8d0330f1745

//  #牛客春招刷题训练营# https://www.nowcoder.com/discuss/726480854079250432
//  思路来自题解,我自己写的超时了
#include <iostream>
using namespace std;

int main() {
  ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
  int t;
  cin >> t;
  int x;
  while(t--){
    cin >> x;
    int count = 0;//----------记录素因子的个数
    int i = 2;
    while(x > 1 && i * i <= x){//-------通过i * i <= x剪枝防止超时
      while(x % i == 0){//--------素因子处理
        x /= i;
        count++;
      }
      i++;
    }
    if(x > 1){//---------前面的剪枝无法处理x中有大于大于根号下x的素因子,所以这里加了个特判
      count++;
    }
    if (count&1){//--------素因子数为奇数
      cout << "kou" << '\n';
    }
    else{
      cout << "yukari" << '\n';
    }
  }
}
// 64 位输出请用 printf("%lld")

#写题解领奖励##牛客春招刷题训练营#
全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务