Skip to content

Commit 020ab4f

Browse files
committed
2 parents 24f8e69 + e75176c commit 020ab4f

12 files changed

+143
-75
lines changed

.verify-helper/timestamps.remote.json

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
2-
"kyopro/test/BIT_yosupo-judge.test.cpp": "2020-05-19 18:09:31 +0900",
3-
"kyopro/test/LCA_yosupo-judge.test.cpp": "2020-05-19 18:09:31 +0900",
4-
"kyopro/test/LIS_dp_aoj.test.cpp": "2020-05-19 18:09:31 +0900",
5-
"kyopro/test/cumulative-sum_yosupo-judge.test.cpp": "2020-06-06 13:57:11 +0900",
6-
"kyopro/test/dijkstra_aoj.test.cpp": "2020-05-19 18:09:31 +0900",
7-
"kyopro/test/dijkstra_path_yosupo-judge.test.cpp": "2020-05-19 18:59:30 +0900",
8-
"kyopro/test/kth-shortest-path_yen_yukicoder.test.cpp": "2020-06-03 00:55:36 +0900",
9-
"kyopro/test/lcm_aoj.test.cpp": "2020-05-19 18:09:31 +0900",
10-
"kyopro/test/segtree_yosupo-judge.test.cpp": "2020-05-21 02:14:52 +0900",
11-
"kyopro/test/sparsetable_yosupo-judge.test.cpp": "2020-05-19 18:09:31 +0900",
12-
"kyopro/test/template_yosupo-judge.test.cpp": "2020-05-13 23:17:59 +0900",
13-
"kyopro/test/unionfind_yosupo-judge.test.cpp": "2020-05-19 18:09:31 +0900",
14-
"kyopro/test/warshallfloyd_aoj.test.cpp": "2020-05-19 18:09:31 +0900"
2+
"kyopro/test/BIT_yosupo-judge.test.cpp": "2020-07-11 16:18:51 +0900",
3+
"kyopro/test/LCA_yosupo-judge.test.cpp": "2020-07-11 16:18:51 +0900",
4+
"kyopro/test/LIS_dp_aoj.test.cpp": "2020-07-11 16:18:51 +0900",
5+
"kyopro/test/cumulative-sum_yosupo-judge.test.cpp": "2020-07-11 16:18:51 +0900",
6+
"kyopro/test/dijkstra_aoj.test.cpp": "2020-07-11 16:18:51 +0900",
7+
"kyopro/test/dijkstra_path_yosupo-judge.test.cpp": "2020-07-11 16:18:51 +0900",
8+
"kyopro/test/kth-shortest-path_yen_yukicoder.test.cpp": "2020-07-11 16:18:51 +0900",
9+
"kyopro/test/lcm_aoj.test.cpp": "2020-07-11 16:18:51 +0900",
10+
"kyopro/test/segtree_yosupo-judge.test.cpp": "2020-07-11 16:18:51 +0900",
11+
"kyopro/test/sparsetable_yosupo-judge.test.cpp": "2020-07-11 16:18:51 +0900",
12+
"kyopro/test/template_yosupo-judge.test.cpp": "2020-07-11 16:18:51 +0900",
13+
"kyopro/test/unionfind_yosupo-judge.test.cpp": "2020-07-18 14:56:14 +0900",
14+
"kyopro/test/warshallfloyd_aoj.test.cpp": "2020-07-11 16:18:51 +0900"
1515
}

kyopro/Source/Source.cpp

+23-25
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Be accepted!
66
⊂   ノ    ・゜+.
77
 しーJ   °。+ *´¨)
88
         .· ´¸.·*´¨) ¸.·*¨)
9-
          (¸.·´ (¸.·'* ☆
9+
          (¸.·´ (¸.·'* ☆
1010
*/
1111

1212
#include <cstdio>
@@ -36,7 +36,7 @@ Be accepted!
3636
//using namespace boost::multiprecision;
3737

3838
//#pragma gcc target ("avx2")
39-
//#pragma gcc optimization ("o3")
39+
//#pragma gcc optimization ("Ofast")
4040
//#pragma gcc optimization ("unroll-loops")
4141
#define rep(i, n) for(int i = 0; i < (n); ++i)
4242
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
@@ -52,9 +52,6 @@ Be accepted!
5252
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
5353
#define prints(s) printf("%s\n", s.c_str()) //string出力
5454
#define all(x) (x).begin(), (x).end()
55-
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
56-
#define pb push_back
57-
#define rpriq priq<int, vector<int>, greater<int>>
5855
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
5956
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
6057
#define Please return
@@ -63,8 +60,8 @@ Be accepted!
6360
#define inf numeric_limits<double>::infinity();
6461
#define linf numeric_limits<long double>::infinity()
6562

66-
6763
using ll = long long;
64+
using ull = unsigned long long;
6865

6966
constexpr int INF = 1073741823;
7067
constexpr int MINF = -1073741823;
@@ -75,29 +72,29 @@ const long double PI = acosl(-1.0L);
7572

7673
using namespace std;
7774

78-
void scans(string& str) {
79-
char c;
80-
str = "";
81-
scanf("%c", &c);
82-
if (c == '\n')scanf("%c", &c);
83-
while (c != '\n' && c != -1 && c != ' ') {
84-
str += c;
85-
scanf("%c", &c);
86-
}
75+
void scans(string & str) {
76+
char c;
77+
str = "";
78+
scanf("%c", &c);
79+
if (c == '\n')scanf("%c", &c);
80+
while (c != '\n' && c != -1 && c != ' ') {
81+
str += c;
82+
scanf("%c", &c);
83+
}
8784
}
8885

8986
void scanc(char& str) {
90-
char c;
91-
scanf("%c", &c);
92-
if (c == -1)return;
93-
while (c == '\n') {
94-
scanf("%c", &c);
95-
}
96-
str = c;
87+
char c;
88+
scanf("%c", &c);
89+
if (c == -1)return;
90+
while (c == '\n') {
91+
scanf("%c", &c);
92+
}
93+
str = c;
9794
}
9895

9996
double acot(double x) {
100-
return PI / 2 - atan(x);
97+
return PI / 2 - atan(x);
10198
}
10299

103100
ll LSB(ll n) { return (n & (-n)); }
@@ -106,9 +103,10 @@ ll LSB(ll n) { return (n & (-n)); }
106103

107104

108105

106+
109107
int main() {
110108

111109

112110

113-
Please AC;
114-
}
111+
Please AC;
112+
}
File renamed without changes.

kyopro/kyopro.vcxproj

+9-7
Original file line numberDiff line numberDiff line change
@@ -191,21 +191,19 @@
191191
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
192192
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
193193
</ClCompile>
194-
<ClCompile Include="library\others\cumulative-sum.cpp">
194+
<ClCompile Include="library\math\prime_factor.cpp">
195195
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
196196
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
197197
</ClCompile>
198-
<ClCompile Include="library\others\doubling.cpp">
198+
<ClCompile Include="library\others\cumulative-sum.cpp">
199199
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
200200
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
201201
</ClCompile>
202-
<ClCompile Include="library\others\modint.cpp">
203-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
204-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
202+
<ClCompile Include="library\others\doubling.cpp">
205203
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
206204
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
207205
</ClCompile>
208-
<ClCompile Include="library\math\comb.cpp">
206+
<ClCompile Include="library\others\modint.cpp">
209207
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
210208
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
211209
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
@@ -266,6 +264,10 @@
266264
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
267265
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
268266
</ClCompile>
267+
<ClCompile Include="test\prime_factor_yosupo-judge.test.cpp">
268+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
269+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
270+
</ClCompile>
269271
<ClCompile Include="test\segtree_yosupo-judge.test.cpp">
270272
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
271273
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
@@ -290,7 +292,6 @@
290292
<ItemGroup>
291293
<None Include="cpp.hint" />
292294
<None Include="docs\BIT.md" />
293-
<None Include="docs\comb.md" />
294295
<None Include="docs\cumulative-sum.md" />
295296
<None Include="docs\dijkstra.md" />
296297
<None Include="docs\dijkstra_path.md" />
@@ -303,6 +304,7 @@
303304
<None Include="docs\LCA_weighted.md" />
304305
<None Include="docs\LIS_dp.md" />
305306
<None Include="docs\modint.md" />
307+
<None Include="docs\prime_factor.md" />
306308
<None Include="docs\segtree.md" />
307309
<None Include="docs\sparsetable.md" />
308310
<None Include="docs\splaytree.md" />

kyopro/kyopro.vcxproj.filters

+7-4
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@
5858
<ClCompile Include="library\graph\warshallfloyd.cpp">
5959
<Filter>Library\Graph</Filter>
6060
</ClCompile>
61-
<ClCompile Include="library\math\comb.cpp">
62-
<Filter>Library\Math</Filter>
63-
</ClCompile>
6461
<ClCompile Include="library\math\gcd_lcm.cpp">
6562
<Filter>ソース ファイル</Filter>
6663
</ClCompile>
@@ -127,6 +124,12 @@
127124
<ClCompile Include="test\cumulative-sum_yosupo-judge.test.cpp">
128125
<Filter>ソース ファイル</Filter>
129126
</ClCompile>
127+
<ClCompile Include="library\math\prime_factor.cpp">
128+
<Filter>ソース ファイル</Filter>
129+
</ClCompile>
130+
<ClCompile Include="test\prime_factor_yosupo-judge.test.cpp">
131+
<Filter>ソース ファイル</Filter>
132+
</ClCompile>
130133
</ItemGroup>
131134
<ItemGroup>
132135
<None Include="cpp.hint" />
@@ -144,11 +147,11 @@
144147
<None Include="docs\LCA.md" />
145148
<None Include="docs\LCA_weighted.md" />
146149
<None Include="docs\wershallfloyd.md" />
147-
<None Include="docs\comb.md" />
148150
<None Include="docs\gcd_lcm.md" />
149151
<None Include="docs\doubling.md" />
150152
<None Include="docs\modint.md" />
151153
<None Include="docs\kth-shortest-path_yen.md" />
152154
<None Include="docs\cumulative-sum.md" />
155+
<None Include="docs\prime_factor.md" />
153156
</ItemGroup>
154157
</Project>

kyopro/library/datastructure/unionfind.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* @title unionfind
33
* @docs kyopro/docs/unionfind.md
44
*/
@@ -65,7 +65,7 @@ struct unionfind {
6565
vector<ll> leaf(ll a) {
6666
vector<ll> x;
6767
ll n = par.size();
68-
for (ll i = 0; i < n; ++i)if (same(a, i))x.pb(i);
68+
for (ll i = 0; i < n; ++i)if (same(a, i))x.push_back(i);
6969
return x;
7070
}
7171

kyopro/library/math/comb.cpp

-16
This file was deleted.

kyopro/library/math/prime_factor.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
map<ll, int> prime_factor(ll a) {
2+
map<ll, int> ret;
3+
for (ll x = 2; x * x <= a; ++x) {
4+
while (not(a % x))++ret[x], a /= x;
5+
}
6+
if (a != 1)++ret[a];
7+
return ret;
8+
}

kyopro/library/others/modint.cpp

+56-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,26 @@
55

66
template<int mod>
77
struct modint {
8-
int val;
8+
int val, size;
99

10-
modint() : val(0) {};
11-
modint(ll x) : val(x >= 0 ? x % mod : (mod + x % mod) % mod) {};
10+
vector<ll> fac, inv, facinv;
11+
12+
modint() : val(0), size(0) {};
13+
modint(ll x) : val(x >= 0 ? x % mod : (mod + x % mod) % mod), size(0) {};
14+
15+
//siz <= 1e7 くらい
16+
void cominit(const int siz) {
17+
size = siz;
18+
fac.assign(siz + 1, 0);
19+
inv.assign(siz + 1, 0);
20+
facinv.assign(siz + 1, 0);
21+
fac[0] = fac[1] = facinv[0] = facinv[1] = inv[0] = 1;
22+
for (ll i = 2; i <= siz; ++i) {
23+
fac[i] = fac[i - 1] * i % mod;
24+
inv[i] = mod - inv[mod % i] * (mod / i) % mod;
25+
facinv[i] = facinv[i - 1] * inv[i] % mod;
26+
}
27+
}
1228

1329
modint& operator=(const modint& x) {
1430
val = x.val;
@@ -33,6 +49,13 @@ struct modint {
3349
}
3450

3551
modint& operator/=(const modint& x) {
52+
if (x <= size) {
53+
ll num = x.val;
54+
num *= inv[x];
55+
num %= mod;
56+
val = num;
57+
return *this;
58+
}
3659
int a = x.val, b = mod, u = 1, v = 0, t;
3760
while (b > 0) {
3861
t = a / b;
@@ -43,6 +66,16 @@ struct modint {
4366
return *this;
4467
}
4568

69+
modint operator++() {
70+
val = (val + 1 == mod ? 0 : val + 1);
71+
return *this;
72+
}
73+
74+
modint operator--() {
75+
val = (val == 0 ? mod - 1 : val - 1);
76+
return *this;
77+
}
78+
4679
modint operator+(const modint& x) const {
4780
return (modint(*this) += x);
4881
}
@@ -59,6 +92,22 @@ struct modint {
5992
return (modint(*this) /= x);
6093
}
6194

95+
bool operator==(const modint& x)const {
96+
return (val == x.val);
97+
}
98+
99+
bool operator!=(const modint& x)const {
100+
return (val != x.val);
101+
}
102+
103+
bool operator<(const modint& x)const {
104+
return (val < x.val);
105+
}
106+
107+
bool operator>(const modint& x)const {
108+
return (val > x.val);
109+
}
110+
62111
modint pow(ll n) {
63112
modint ret(1), a(val);
64113
while (n > 0) {
@@ -69,5 +118,9 @@ struct modint {
69118
return ret;
70119
}
71120

121+
modint comb(const modint& n, const modint& r) {
122+
return (n < r or n < 0 or r < 0) ? 0 : ((fac[n] * (facinv[r] * facinv[n - r] % mod)) % mod);
123+
}
124+
72125
static int getmod() { return mod; };
73126
};

kyopro/library/template/template.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ using namespace boost::multiprecision;
5959
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
6060
#define prints(s) printf("%s\n", s.c_str()) //string出力
6161
#define all(x) (x).begin(), (x).end()
62-
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
63-
#define pb push_back
64-
#define rpriq priq<int, vector<int>, greater<int>>
6562
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
6663
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
6764
#define Please return
@@ -70,8 +67,8 @@ using namespace boost::multiprecision;
7067
#define inf numeric_limits<double>::infinity();
7168
#define linf numeric_limits<long double>::infinity()
7269

73-
7470
using ll = long long;
71+
using ull = unsigned long long;
7572

7673
constexpr int INF = 1073741823;
7774
constexpr int MINF = -1073741823;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#define PROBLEM "https://judge.yosupo.jp/problem/factorize"
2+
#define IGNORE
3+
4+
#include "../library/template/template.cpp"
5+
6+
#include "../library/math/prime_factor.cpp"
7+
8+
int main() {
9+
10+
int q;
11+
scanf("%d", &q);
12+
while (q--) {
13+
ll a;
14+
scanf("%lld", &a);
15+
auto b = prime_factor(a);
16+
printf("%d\n", (int)b.size());
17+
for (const auto& [p, q] : b)rep(i, q)printf("%lld\n", p);
18+
}
19+
20+
Please AC;
21+
}

0 commit comments

Comments
 (0)