Ural 1428. Jedi Riddle 二分求幂

1428. Jedi Riddle

Time limit: 1.0 second
Memory limit: 64 MB

Background

System administrator Vasily Slipman, also known as Jedi Master, was an outstanding jester. He enciphered gigabyte archive with... Not with cartoon films for children, of course. Well, you have already understood with what. To cut a long story short, Vasily enciphered the archive using a key formed by six unknown numbers, and then he died. Strange inscriptions written by the decedent were found on the surface of his computer’s case. These inscriptions may cast light on the origin of those six numbers which are so essential for people.
It appeared that the greatest human Sins in Mr. Slipman’s opinion are Fear, Anger and Hatred. By the way, nothing was said about terrorism. Hence the greatest human Virtues are Valor, Calmness and Love. Vasily assigned a special Number to each of the Sins and the Virtues. The Numbers of the Sins were found, and now the time has come to calculate the Numbers of the Virtues.

Problem

Let us denote the Number of Fear as A, the Number of Anger as B, the Number of Hatred as C, the Number of Valor as X, the Number of Calmness as Y and the Number of Love as Z. Mr. Slipman chose the Numbers A, B and C so that C-1 is divisible both by A and B, i.e. (C-1) modulo A = (C-1) modulo B = 0. You are to find the integer Numbers X, Y and Z in order to satisfy the following strange equation: X^A + Y^B = Z^C. The inscriptions tell us that X, Y and Z should not be less than 1 and more than 10^50. It was the will of the decedent.

Input

The only line contains the integer Numbers A, B and C (1 ≤ A, B, C ≤ 32).

Output

You should output the desired Numbers X, Y and Z. Each Number should be printed in a separate line. If the problem has several solutions, you should output any of them.

Sample

input output
2 2 3
10
5
5
Problem Author: Ilya Grebnov, Dmitry Kovalioff, Nikita Rybak
Problem Source: Timus Top Coders: First Challenge
已知A、B、C,然后要求满足X^A + Y^B = Z^C,求出X、Y、Z。
题目中很巧妙的条件是(C-1)%A= (C-1)%B=0。假设C=2,则x^a+y^b=2^c 

因为2^(c-1) + 2^(c-1) =  2^c所以 x^a == 2^(c-1), y^b = 2^(c-1)即 x == 2^((c-1)/a), y== 2^((c-1)/b)。

#include <iostream>
#include <cstdio>
using namespace std;
long long llpow(int x,int y)
{
    long long ans=1;
    while(y!= 0)
    {
        if (y%2 == 1)
        {
            ans*= x;
        }
        y /= 2;
        x *= x;
    }
    return ans;
}

int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    cout<<llpow(2,(c-1)/a)<<endl<<llpow(2,(c-1)/b)<<endl<<2<<endl;
    return 0;
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值