判正误

链接:https://ac.nowcoder.com/acm/contest/3003/G
来源:牛客网

牛可乐有七个整数 a,b,c,d,e,f,g\text{}a,b,c,d,e,f,ga,b,c,d,e,f,g 并且他猜想 ad+be+cf=ga^d+b^e+c^f=gad+be+cf=g。但  牛可乐无法进行如此庞大的计算。
请验证 牛可乐的猜想是否成立。

输入描述:

第一行一个正整数 T,表示有 T 组数据。
每组数据输入一行七个整数 a,b,c,d,e,f,g\text{}a,b,c,d,e,f,ga,b,c,d,e,f,g 。
保证 1≤T≤10001\leq T \leq 10001T1000 , −109≤a,b,c,g≤109-10^9\leq a,b,c,g\leq 10^9109a,b,c,g109 , 0≤d,e,f≤1090\leq d,e,f\leq 10^90d,e,f109 保证不会出现指数和底数同为 0 的情况。

输出描述:

每组数据输出一行,若猜想成立,输出 Yes ,否则输出 No。
示例1

输入

2
1 1 4 5 1 4 258
114514 1919810 1 2 3 4 1

输出

Yes
No

说明

15+11+44=2581^5+1^1+4^4=25815+11+44=258
1145142+19198103+14≠1114514^2+1919810^3+1^4\neq 11145142+19198103+14=1
 
题解:对a b c 分别进行多次取模处理然后计算   
 
#include 
using namespace std;
const int mod[] = {2, 3, 5, 7, 11, 31, 71, 97, 233, 397, 433, 449, 607, 857, 10007, 21179, 36251, 44579, 62003, 72883, 97843, 139991, 232013, 369353, 681521, 692711, 777241, 822821, 1956761, 2145137, 2915837, 6229117, 7788787, 13743493, 17331841, 19260817, 19269293, 19959809, 21006959, 23937083, 24410849, 28452757, 28478603, 29229359, 35570827, 35604011, 35875487, 37370863, 38303347, 38475517, 38819149, 40455791, 44021539, 45641993, 46531301, 48866749, 50529641, 52634191, 52790587, 55180799, 56971613, 58259351, 60954737, 62207269, 63367453, 65072599, 66017821, 67952779, 69475349, 74689217, 77059907, 77907121, 79391659, 84768797, 85584601, 85724879, 85756609, 86850899, 91783511, 92331541, 94519499, 96375241, 99033413, 99486311, 100569829, 106873549, 109329881, 109913681, 111186487, 111894067, 112136617, 112417363, 114011921, 119143363, 122994493, 123747781, 124001021, 126515639, 128191039, 128767909, 132222763, 133587661, 139644719, 145641527, 153388423, 155187077, 156883333, 157989581, 159538063, 161488643, 164039129, 166070447, 169181543, 169554227, 173564801, 175742867, 185469637, 187203899, 191263223, 198691817, 204144887, 211631201, 217903877, 218028203, 220073423, 228143453, 228667423, 232064653, 240519263, 245647159, 247586411, 247936121, 250949197, 253413211, 253464329, 260572729, 260590409, 262887773, 265711423, 266763641, 273585149, 276472817, 276500531, 280543667, 280649591, 281385491, 291366337, 293273159, 296973107, 302890501, 306568693, 315614297, 316729409, 317617121, 320337781, 320613497, 321322823, 324691051, 325963067, 327184157, 329900633, 330670159, 332058781, 332213669, 332300869, 334382221, 341895677, 347938237, 349011827, 349347503, 349906439, 353796941, 364557253, 364755931, 367946441, 372413831, 374358983, 379589897, 381149689, 389431873, 404683493, 405216109, 405495029, 408142403, 408989747, 410841979, 410935093, 412405351, 412592459, 412722139, 412990573, 418171483, 421270357, 424233613, 427938449, 428492083, 429962881, 430883569, 434988383, 435941201, 438816151, 440052953, 440143589, 444693631, 453646433, 455847109, 456640189, 457911511, 458185237, 463116761, 463861417, 469275953, 471298573, 471712513, 478267417, 483824813, 494828483, 497397293, 499657393, 507957479, 512906621, 519346459, 519879973, 520094713, 523213693, 525673273, 529575763, 529883803, 533887031, 534260809, 535328309, 541992667, 542253071, 544780177, 545567609, 552922529, 555129893, 555820037, 558473471, 563484017, 571310471, 578121241, 582251063, 583825639, 584121323, 592038487, 599098811, 601467677, 610073969, 615059213, 619220713, 622457177, 627412609, 630547919, 632342989, 637357363, 638865419, 648268013, 650007487, 651564761, 654115433, 661281713, 662664461, 667914281, 682988213, 691099121, 691445809, 692038043, 692411953, 698620943, 699007259, 701164631, 706806461, 707096251, 707697451, 709566589, 719095829, 725756807, 736880491, 739603867, 743026709, 744236861, 744396049, 747393791, 749395103, 760341121, 762934307, 773124059, 773195911, 776162609, 781629113, 781884613, 786120631, 788314343, 788898377, 788939293, 790209983, 791933183, 796328783, 798643889, 802280047, 803293991, 803847559, 809752739, 818520473, 820434047, 826810489, 829359959, 829707427, 836587463, 841011167, 843763253, 849410557, 851226437, 853058471, 853168793, 853778327, 859086391, 860720017, 863193077, 873061181, 888803059, 893035529, 900902953, 904636883, 917949577, 921817139, 922328707, 931449133, 933074827, 933156233, 935241721, 935632799, 939948881, 957119773, 961329913, 965269573, 965337949, 967551691, 971080093, 973578143, 976825877, 985100197, 985413691, 986124823, 990650057, 998244353, 999058883, 1000000007};
int ff(int a, int m) {
  return (a % m + m) % m;
}
int Pow(int a, int b, int c) {
  int ret = 1;
  while (b) {
    if (b & 1) ret = ret * 1ll * a % c;
    a = a * 1ll * a % c;
    b >>= 1;
  }
  return ret;
}
int a, b, c, d, e, f, g;
 
bool check(int m) {
  return ((Pow(ff(a, m), d, m) + Pow(ff(b, m), e, m)) % m + Pow(ff(c, m), f, m)) % m == ff(g, m);
}
 
int main() {
  int T;
  cin >> T;
  while (T--) {
    // cerr << T << endl;
    cin >> a >> b >> c >> d >> e >> f >> g;
    assert((a || d) && (b || e) && (c || f));
    assert(min(a, min(b, min(c, g))) >= -1e9 && max(a, max(b, max(c, g))) <= 1e9 && min(d, min(e, f)) >= 0 && max(d, max(e, f)) <= 1e9);
    bool flag = 1;
    for (int i = 0; i < 349; ++i) if (!check(mod[i])) {flag = 0; break;}
    puts(flag ? "Yes" : "No");
  }
  return 0;
}

 

你可能感兴趣的:(判正误)