nyoj 408 Board Game Dice

版权声明:本文为博主原创文章,转载需注明出处。 https://blog.csdn.net/Hearthougan/article/details/24921175

题目来源:http://acm.nyist.net/JudgeOnline/problem.php?pid=408

题意:给定n, m,问当m的x次方大于等于n时,(m^x * x)与n的真分数是多少。

#include<stdio.h>

typedef long long LL;

LL  gcd(LL a, LL b)//*这就是那个求最大公约数的函数。一个模版。*//
{
	if(b == 0)
        return a;
	return gcd(b,a%b);
}

int main()
{
    LL temp, n, m, tmp;
	int T,i,j, kcase = 1;
	scanf("%d", &T);
	while(T--)
	{
	   scanf("%lld %lld",&n,&m);
	   tmp = 1, i = 0;
	   while(1)
       {
           i++;
           tmp *= m;
           if(tmp >= n)
            break;
       }
	   tmp *= i;
	   temp = gcd(tmp, n);
	   tmp = tmp/temp;
	   n = n/temp;
	   printf("Case %d: %lld/%lld\n", kcase++, tmp, n);
	}
	return 0;
}


阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页