【數論和基礎數學】整除和取餘-取石子游戲

取石子游戲

在這裏插入圖片描述

在這裏插入圖片描述

#include<iostream>
using namespace std;
int gcd(int a, int b){
    if(b == 0){
        return a;
    }
    return gcd(b, a%b);
}
void Judge(int gcdd, int n){
    int num;
    // 判斷有幾個最大公約數
    for(int i = gcdd; i <= n; i++){
        if(i % gcdd == 0){
            num++;
        }
    }
    // 判斷次數
    if(num % 2 == 0){cout << "suantou" << endl;}
    if(num % 2 != 0){cout << "huaye" << endl;}
}
int main(){
    int t;
    scanf("%d", &t);
    while(t--){
        int n, a, b;
        scanf("%d %d %d", &n, &a, &b);
        int gcdd = gcd(a, b);
        Judge(gcdd, n);
    }
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章