-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.cpp
More file actions
283 lines (274 loc) · 6.78 KB
/
Copy pathcode.cpp
File metadata and controls
283 lines (274 loc) · 6.78 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long int
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordred_set;
//member functions :(-- use less_equal to make it multiset)
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ff first
#define se second
#define mp make_pair
#define pb push_back
#define print(x) cout<<x<<"\n"
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define nl cout<<"\n";
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
#define minv(a) (*min_element((a).begin(), (a).end()))
#define maxv(a) (*max_element((a).begin(), (a).end()))
#define mina(a,n) (*min_element(a, a+n))
#define maxa(a,n) (*max_element(a, a+n))
#define IO cin.sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define lb(a, x) (lower_bound((a).begin(), (a).end(), (x))-(a).begin())
#define ub(a, x) (upper_bound((a).begin(), (a).end(), (x))-(a).begin())
#define all(x) (x).begin(), (x).end()
#define rall(x) x.rbegin(), x.rend()
#define printv(v) for(auto e : v) cout<<e<<" "
#define pushv(v, n) for(int i=0;i<n;i++) cin>>v[i]
#define bsearch(v, x) binary_search(v.begin(), v.end(), x)
#define sz(x) ((int)(x).size())
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef map<int, int> mi;
typedef unordered_map<int, int> umi;
typedef priority_queue<int> mxpq;
typedef priority_queue <int, vector<int>, greater<int>> mnpq;
const int mod = 1e9+7;
const int inf = (int)1e9;
const double eps = 1e-9;
const int mxm = 1e5 + 5;
//-------------------DSU-----------------
vector<int>parent;
void make_set(int n){
parent.resize(n+5);
for(int i=0;i<n+5;i++){
parent[i]=i;
}
}
int find(int x){
if( parent[x] == x) {
return x;
}
return parent[x]=find(parent[x]);
}
bool union_set(int x,int y){
int p=find(x);
int q=find(y);
if(p==q){
return true;
}
parent[p]=q;
return false;
}
//-----------------digit sum of no---------------
int digitsum(int n)
{
int sum = 0;
while (n != 0) {
sum = sum + n % 10;
n = n / 10;
}
return sum;
}
//---------------LCM---------------
int lcm(int a, int b)
{
int g=__gcd(a, b);
return a/g*b;
}
//---------prime checker-----------------
void prime(bool isPrime[]){
for(int i=0;i<=1000000;i++){
isPrime[i]=1;
}
isPrime[1]=0;
isPrime[0]=0;
for(int i=2;i*i<=1000000;i++){
if(isPrime[i]==1){
for(int j=i*i;j<=1000000;j+=i){
isPrime[j]=0;
}
}
}
}
//---------smallest prime factor-------------
void _spf(int spf[]){
for(int i=0;i<=1e6;i++){
spf[i] = i;
}
for(int i=2;i*i<=1e6;i++){
if(spf[i]==i){
for(int j=i*i;j<=1e6;j+=i){
if(spf[j]==j){
spf[j]=i;
}
}
}
}
}
//-------------no ofg distinct gcd of array in (mx)log(mx)------------
vector<int> distinctGCDs(vector<int> &arr, int N){
vi distinct;int M = -1, ans = 0; umi Mp;
for (int i = 0; i < N; i++) {
M = max(M, arr[i]);
Mp[arr[i]] = 1;
}
for (int i = 1; i <= M; i++) {// variable to check current GCD
int currGcd = 0;// iterate over all multiples of i
for (int j = i; j <= M; j += i) {// If j is present in A
if (Mp[j]) {// calculate gcd of all encountered | multiples of i
currGcd = __gcd(currGcd, j);// current GCD is possible
if (currGcd == i) {
distinct.pb(currGcd); ans++;break;
} } }} // return answer
return distinct;
}
//------------factorial------------------------
void fact(int fac[])
{
fac[0]=1;
for(int i=1;i<=1e6;i++){
fac[i] = fac[i-1]*i; // (a*b)%m = ((a%m)*(b%m))%m
fac[i]%=mod;
}
}
//---------binary exponantiation----------------
int binExp(int x,int n)
{
int res=1;
while(n){
if(n%2==1){
res*=x;
res%=mod;
}
n/=2;
x*=x;
x%=mod;
}
return res;
}
//--------------ncr-------------------------------
int ncr(int n,int r,int fac[])
{
int temp1 = fac[n];
int temp2 = fac[n-r]*fac[r];
temp2%=mod;
int temp3 = binExp(temp2,mod-2); // temp3 is the modulo inverse
temp1*=temp3;
temp1%=mod;
return temp1;
}
//------------prime factorization------------------
vector<long long> div(long long n) {
vector<long long> f;
for (long long d = 2; d * d <= n; d++) {
while (n % d == 0) {
f.push_back(d);
n /= d;
}
}
if (n > 1)
f.push_back(n);
return f;
}
//------------Dijekstra Algorithm----------------------
void dijekstra(){
int n, m;
cin >> n >> m;
vector<pair<int, int>> v[n];
int dis[n];
int par[n];
int x, y, z;
for (int i = 0; i < m; i++)
{
cin >> x >> y >> z;
x--;
y--;
v[x].push_back({z, y});
v[y].push_back({z, x});
}
for (int i = 0; i < n; i++)
{
dis[i] = inf;
par[i] = i;
}
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
pq.push({0, 0});
dis[0] = 0;
while (!pq.empty())
{
auto p = pq.top();
int xi = p.second;
int xv = p.first;
pq.pop();
if (xv > dis[xi])
continue;
for (int i = 0; i < sz(v[xi]); i++)
{
int yi = v[xi][i].second;
int yv = v[xi][i].first;
if (dis[yi] <= xv + yv)
continue;
dis[yi] = xv + yv;
par[yi] = xi;
pq.push({dis[yi], yi});
}
}
if (dis[n - 1] < inf)
{
vector<int> a;
int ind = n - 1;
while (ind != par[ind])
{
a.push_back(ind);
ind = par[ind];
}
a.push_back(0);
for (int i = sz(a) - 1; i >= 0; i--)
{
cout << a[i] + 1 << ' ';
}
}
else
cout << -1;
}
//----------------------------------solve function-----------------------------------
void solve(){
int n;cin>>n;
vector<int> div(100001,-1);
int j=1;
while(n--){
int x,y;cin>>x>>y;
int st=j-y;int end=j-1;
int cnt=0;
for(int i=1;i*i<=x;i++){
if(x%i==0){
if(div[i]<=end&&div[i]>=st) cnt--;
cnt++;
if((x/i)!=i){
if(div[x/i]<=end&&div[x/i]>=st) cnt--;
cnt++;
}
div[i]=j;
div[x/i]=j;
}
}
cout<<cnt<<endl;
j++;
}
}
int32_t main(){
IO;
int t=1;
//cin>>t;
while(t--){
solve();
}
return 0;
}