LightOJ - 1116-Ekka Dokka(思维)

链接:

https://vjudge.net/problem/LightOJ-1116

题意:

Ekka and his friend Dokka decided to buy a cake. They both love cakes and that's why they want to share the cake after buying it. As the name suggested that Ekka is very fond of odd numbers and Dokka is very fond of even numbers, they want to divide the cake such that Ekka gets a share of N square centimeters and Dokka gets a share of M square centimeters where N is odd and M is even. Both N and M are positive integers.

They want to divide the cake such that N * M = W, where W is the dashing factor set by them. Now you know their dashing factor, you have to find whether they can buy the desired cake or not.

思路:

考虑,奇数*偶数不可能为奇数。
将n/2变成奇数即可。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>

using namespace std;
typedef long long LL;
const int INF = 1e9;

const int MAXN = 1e6+10;
const int MOD = 1e9+7;

int main()
{
    int t, cnt = 0;
    LL n, x;
    scanf("%d", &t);
    while(t--)
    {
        scanf("%lld", &n);
        printf("Case %d: ", ++cnt);
        if (n%2)
            puts("Impossible");
        else
        {
            LL tmp = n;
            while(n%2==0)
                n/=2;
            printf("%lld %lld\n", n, tmp/n);
        }
    }

    return 0;
}

猜你喜欢

转载自www.cnblogs.com/YDDDD/p/11817278.html