@@ -518,23 +518,23 @@ poly operator*(poly a, const num b) {
518
518
}
519
519
OP (*, *=) OP(+, +=) OP(-, -=);
520
520
poly modK (poly a, int k) { return {a.begin (), a.begin () + min (k, sz (a))}; }
521
- poly inverse (poly A) {
522
- poly B = poly ({num (1 ) / A[0 ]});
523
- while (sz (B) < sz (A)){
524
- poly C = B*modK (A, 2 *sz (B));
525
- C = poly (C.begin ()+sz (B), C.end ());
526
- C = modK (B*C, sz (B));
527
- C.insert (C.begin (), sz (B), 0 );
528
- B -= C;
529
- }
530
- return modK (B, sz (A));
531
- }
532
521
// poly inverse(poly A) {
533
522
// poly B = poly({num(1) / A[0]});
534
- // while (sz(B) < sz(A))
535
- // B = modK(B * (poly({num(2)}) - modK(A, 2*sz(B)) * B), 2 * sz(B));
523
+ // while (sz(B) < sz(A)){
524
+ // poly C = B*modK(A, 2*sz(B));
525
+ // C = poly(C.begin()+sz(B), C.end());
526
+ // C = modK(B*C, sz(B));
527
+ // C.insert(C.begin(), sz(B), 0);
528
+ // B -= C;
529
+ // }
536
530
// return modK(B, sz(A));
537
531
// }
532
+ poly inverse (poly A) {
533
+ poly B = poly ({num (1 ) / A[0 ]});
534
+ while (sz (B) < sz (A))
535
+ B = modK (B * (poly ({num (2 )}) - modK (A, 2 *sz (B)) * B), 2 * sz (B));
536
+ return modK (B, sz (A));
537
+ }
538
538
poly &operator /=(poly &a, poly b) {
539
539
if (sz (a) < sz (b))
540
540
return a = {};
@@ -651,12 +651,12 @@ bool checkEqual(mine::poly a, MIT::poly b) {
651
651
for (int i = 0 ; i < ml; i++)
652
652
if (a[i].x != b[i].v )
653
653
return false ;
654
- for (int i = ml; i < sz (a); i++)
655
- if (a[i].x != 0 )
656
- return false ;
657
- for (int i = ml; i < sz (b); i++)
658
- if (b[i].v != 0 )
659
- return false ;
654
+ // for (int i = ml; i < sz(a); i++)
655
+ // if (a[i].x != 0)
656
+ // return false;
657
+ // for (int i = ml; i < sz(b); i++)
658
+ // if (b[i].v != 0)
659
+ // return false;
660
660
return true ;
661
661
}
662
662
@@ -685,19 +685,17 @@ template <class A, class B> void testBinary(string name, A f1, B f2, int mxSz =
685
685
assert (checkEqual (res, t));
686
686
}
687
687
cout << name << " tests passed!" << endl;
688
+ auto a = genVec (mxSz);
689
+ auto b = genVec (mxSz/2 );
688
690
{
689
691
timeit x (" mine" );
690
692
for (int it=0 ; it<NUMITERS; it++) {
691
- auto a = genVec ((rand () % mxSz) + 1 );
692
- auto b = genVec ((rand () % mxSz) + 1 );
693
693
f1 (a.first , b.first );
694
694
}
695
695
}
696
696
{
697
697
timeit x (" MIT" );
698
698
for (int it=0 ; it<NUMITERS; it++) {
699
- auto a = genVec ((rand () % mxSz) + 1 );
700
- auto b = genVec ((rand () % mxSz) + 1 );
701
699
f2 (a.second , b.second );
702
700
}
703
701
}
@@ -713,17 +711,16 @@ template <class A, class B> void testUnary(string name, A f1, B f2, int mxSz = 5
713
711
assert (checkEqual (res, t));
714
712
}
715
713
cout << name + " tests passed!" << endl;
714
+ auto a = genVec (mxSz);
716
715
{
717
716
timeit x (" mine" );
718
717
for (int it=0 ; it<NUMITERS; it++) {
719
- auto a = genVec ((rand () % mxSz) + 1 );
720
718
f1 (a.first );
721
719
}
722
720
}
723
721
{
724
722
timeit x (" MIT" );
725
723
for (int it=0 ; it<NUMITERS; it++) {
726
- auto a = genVec ((rand () % mxSz) + 1 );
727
724
f2 (a.second );
728
725
}
729
726
}
@@ -745,25 +742,17 @@ template <class A, class B> void testPow(string name, A f1, B f2, int mxSz = 5,
745
742
assert (checkEqual (res, t));
746
743
}
747
744
cout << name + " tests passed!" << endl;
745
+ auto a = genVec ((rand () % mxSz) + 1 );
746
+ int p = mxSz;
748
747
{
749
748
timeit x (" mine" );
750
749
for (int it = 0 ; it < NUMITERS; it++) {
751
- auto a = genVec ((rand () % mxSz) + 1 );
752
- int pref = rand ()%mxPref;
753
- for (int j=0 ; j<pref; j++)
754
- a.first .insert (a.first .begin (), mine::num (0 ));
755
- int p = rand () % mxSz;
756
750
f1 (a.first , p);
757
751
}
758
752
}
759
753
{
760
754
timeit x (" mit" );
761
755
for (int it = 0 ; it < NUMITERS; it++) {
762
- auto a = genVec ((rand () % mxSz) + 1 );
763
- int pref = rand ()%mxPref;
764
- for (int j=0 ; j<pref; j++)
765
- a.second .insert (a.second .begin (), MIT::num (0 ));
766
- int p = rand () % mxSz;
767
756
f2 (a.second , p);
768
757
}
769
758
}
@@ -780,19 +769,17 @@ template <class A, class B> void testEval(string name, A f1, B f2, int mxSz = 5)
780
769
assert (checkEqual (res, t));
781
770
}
782
771
cout << name + " tests passed!" << endl;
772
+ auto a = genVec (mxSz);
773
+ auto b = genVec (mxSz);
783
774
{
784
775
timeit x (" mine" );
785
776
for (int it = 0 ; it < NUMITERS; it++) {
786
- auto a = genVec ((rand () % mxSz) + 1 );
787
- auto b = genVec ((rand () % mxSz)+1 );
788
777
f1 (a.first , b.first );
789
778
}
790
779
}
791
780
{
792
781
timeit x (" MIT" );
793
782
for (int it = 0 ; it < NUMITERS; it++) {
794
- auto a = genVec ((rand () % mxSz) + 1 );
795
- auto b = genVec ((rand () % mxSz)+1 );
796
783
f2 (a.second , b.second );
797
784
}
798
785
}
@@ -810,19 +797,17 @@ template <class A, class B> void testInterp(string name, A f1, B f2, int mxSz =
810
797
assert (checkEqual (res, t));
811
798
}
812
799
cout << name + " tests passed!" << endl;
800
+ auto a = genVec (mxSz);
801
+ auto b = genVec (mxSz);
813
802
{
814
803
timeit x (" mine" );
815
804
for (int it = 0 ; it < NUMITERS; it++) {
816
- auto a = genVec ((rand () % mxSz) + 1 );
817
- auto b = genVec ((rand () % mxSz)+1 );
818
805
f1 (a.first , b.first );
819
806
}
820
807
}
821
808
{
822
809
timeit x (" MIT" );
823
810
for (int it = 0 ; it < NUMITERS; it++) {
824
- auto a = genVec ((rand () % mxSz) + 1 );
825
- auto b = genVec ((rand () % mxSz)+1 );
826
811
f2 (a.second , b.second );
827
812
}
828
813
}
0 commit comments