标签:des style http color os io strong for
Description
Benefit |
You should write a program that help poor students giving the appropriate amount of money to Yaghoub. Of course if there are several answers you go for students‘ benefit which is the lowest of them.
3 2 6 32 1760 7 16
3 55 NO SOLUTION 题意:已知lcm(A, B) = C ,现在知道a和c,求最小的b。 思路:设A = a*b*c*d, B = a*b*c*e,那么我们可以清楚C = a*b*c*d*e,将A和C相除的话,我们就可以得到B除了gcd以外的部分了, 举两个例子:A = a*b*c*d, B = a*b*c*a*b*c*e; A = a*a*a, B = a*a*a*a*b,可以得到如果我们得到的部分和A互质的话,那么这个数就是最小的了,如果不是的话 不断的取gcd来补B的因子,起初以为只要一次就够了,没想到第二个样例#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a%b); } int main() { int t, A, B, C; scanf("%d", &t); while (t--) { scanf("%d%d", &A, &C); if (C % A) { printf("NO SOLUTION\n"); continue; } B = C/A; int g = gcd(A, B); while (g != 1) { B *= g; A /= g; g = gcd(A, B); } printf("%d\n", B); } return 0; }
UVA - 11889 Benefit,布布扣,bubuko.com
标签:des style http color os io strong for
原文地址:http://blog.csdn.net/u011345136/article/details/38656959