1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
| #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
vector<int> func(int n) {
vector<int> ret;
if(n == 0 || n == 1) {
ret.push_back(n);
return ret;
}
int a = 2;
while(n >= a*a) {
if(n%a == 0) {
n /= a;
ret.push_back(a);
}
else {
a++;
}
}
if(n > 1) ret.push_back(n);
return ret;
}
class GeometricProgressions {
public:
int count(int b1, int q1, int n1, int b2, int q2, int n2) {
map<vector<pair<int,int> >,int> m;
vector<int> B1 = func(b1);
vector<int> Q1 = func(q1);
vector<int> B2 = func(b2);
vector<int> Q2 = func(q2);
map<int,int> cnt;
rep(i,B1.size()) {
cnt[B1[i]]++;
}
vector<pair<int,int> > v;
map<int,int>::iterator ite;
for(ite = cnt.begin();ite != cnt.end();ite++) {
v.push_back(make_pair(ite->first,ite->second));
}
m[v]++;
if(q1 == 0) {
if(b1 != 0 && n1 != 1) {
vector<pair<int,int> > res;
res.push_back(make_pair(0,1));
m[res]++;
}
}
else if(b1 != 0 && q1 != 1) {
rep(i,n1-1) {
rep(j,Q1.size()) cnt[Q1[j]]++;
vector<pair<int,int> > res;
map<int,int>::iterator ite;
for(ite = cnt.begin();ite != cnt.end();ite++) {
res.push_back(make_pair(ite->first,ite->second));
}
m[res]++;
}
}
map<int,int> cnt2;
rep(i,B2.size()) {
cnt2[B2[i]]++;
}
vector<pair<int,int> > v2;
for(ite = cnt2.begin();ite != cnt2.end();ite++) {
v2.push_back(make_pair(ite->first,ite->second));
}
m[v2]++;
if(q2 == 0) {
if(b2 != 0 && n2 != 1) {
vector<pair<int,int> > res;
res.push_back(make_pair(0,1));
m[res]++;
}
}
else if(b2 != 0 && q2 != 1) {
rep(i,n2-1) {
rep(j,Q2.size()) cnt2[Q2[j]]++;
vector<pair<int,int> > res;
map<int,int>::iterator ite;
for(ite = cnt2.begin();ite != cnt2.end();ite++) {
res.push_back(make_pair(ite->first,ite->second));
}
m[res]++;
}
}
return m.size();
}
};
|