@@ -18,6 +18,9 @@ inline u128 mul(u128 x, u128 y, u128 c)
18
18
return ans % c;
19
19
}
20
20
21
+ u128 HI (u128 x) { return x>>64 ; };
22
+ u128 LO (u128 x) { return u64 (x); };
23
+
21
24
namespace Prime {
22
25
23
26
int const num_tries = 20 ;
@@ -55,7 +58,7 @@ namespace Prime {
55
58
u128 s = 1 , d = x>>1 ;
56
59
while (!(d&1 )) s++, d>>= 1 ;
57
60
58
- uniform_int_distribution<u64 > rng (2 , u64 (x)-1 );
61
+ uniform_int_distribution<u64 > rng (2 , HI (x)? u64 (- 1ull ): ( u64 ( x)-1 ) );
59
62
60
63
for (int i = 0 ; i < num_tries; i++) {
61
64
u64 p = rng (rd);
@@ -82,10 +85,7 @@ namespace Factor {
82
85
x*=x;
83
86
}
84
87
}
85
-
86
- u128 HI (u128 x) { return x>>64 ; };
87
- u128 LO (u128 x) { return u64 (x); };
88
-
88
+
89
89
struct u256 {
90
90
u128 hi, lo;
91
91
@@ -110,7 +110,7 @@ namespace Factor {
110
110
111
111
inline u128 gcd (u128 a, u128 b) {
112
112
auto ctz = [] (u128 x) {
113
- if (u64 (x)) return __builtin_ctzll (x);
113
+ if (! HI (x)) return __builtin_ctzll (x);
114
114
return 64 + __builtin_ctzll (x>>64 );
115
115
};
116
116
@@ -169,7 +169,7 @@ namespace Factor {
169
169
if (x%2 == 0 ) return 2 ;
170
170
if (x%3 == 0 ) return 3 ;
171
171
172
- uniform_int_distribution<u64 > rng (2 , u64 (x)-1 );
172
+ uniform_int_distribution<u64 > rng (2 , HI (x)? u64 (- 1ull ): ( u64 ( x)-1 ) );
173
173
174
174
for (u128 i = 2 ; i < num_tries; i++) {
175
175
u128 ans = rho (rng (rd), x, i);
@@ -244,4 +244,4 @@ int main()
244
244
printf (" ^" );
245
245
write (cnt, ' \n ' );
246
246
}
247
- }
247
+ }
0 commit comments