UVa 408 - Uniform Generator

传送门UVa 408 - Uniform Generator

据说是用到了数论中的完全剩余系. 刚好今天下午去图书馆借了本<<初等数论>>, 待我先去研究一下... 明天再来补充.

做法是求给出的两个数是否互质, 如果是, 就是Good Choice.

话说为什么我看到GCD第一联想就是我党...

详情见代码 I

---------------------------------------------------------------------------------------------------------------

刚试了一下, 这题也可以简单粗暴地过的, 只要判断cnt = mod之前有没有值为0的step即可. 默默地滚去看书了...

详情见代码 II

--------------------------------------------4.27补充---------------------------------------------

我太高估自己了.....看了一个晚上根本看不懂

----------------------------------------------------------------------------------------------------

代码 I

#include <cstdio>
#include <cmath>

using namespace std;

int GCD(int a, int b)
{
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

int main()
{
    //freopen("input.txt", "r", stdin);
    int a, b;
    while (~scanf("%d%d", &a, &b))
    {
        int temp = GCD(a, b);
        printf("%10d%10d", a, b);
        if (temp == 1)
            printf("    Good Choice\n");
        else
            printf("    Bad Choice\n");
        printf("\n");
    }
    return 0;
}

代码 II


#include <cstdio>
#include <cmath>

using namespace std;

int main()
{
    //freopen("input.txt", "r", stdin);
    int cnt, seed, step, mod;
    while (~scanf("%d%d", &step, &mod))
    {
        cnt = seed = 0;
        printf("%10d%10d", step, mod);
        while (true)
        {
            seed = (seed + step) % mod;
            cnt++;
            if (seed == 0)
            {
                if (cnt == mod)
                    printf("    Good Choice\n");
                else
                    printf("    Bad Choice\n");
                printf("\n");
                break;
            }
        }
    }
    return 0;
}




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值