-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path098-multiplicity.cpp
More file actions
86 lines (83 loc) · 2.06 KB
/
Copy path098-multiplicity.cpp
File metadata and controls
86 lines (83 loc) · 2.06 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
/*
* Multiplicity [1061C]
* Problem: https://codeforces.com/problemset/problem/1061/C
* Verdict: ACCEPTED Solved: 2022-12-26
* Language: C++20 (GCC 11-64)
* Runtime: 2120 ms Memory: 218600 KB
* Tags: data structures, dp, implementation, math, number theory
* Author: BidoTeima
* Source: https://codeforces.com/contest/1061/submission/186777992
*/
/*
ID: BidoTeima
LANG: C++11
TASK:
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void moo(string filename);
void ACPLS(string str = "")
{
if(str=="NOF")return;
if(str.size())
moo(str);
else{
#ifndef ONLINE_JUDGE
freopen("output.txt", "w", stdout);
freopen("input.txt", "r", stdin);
#endif
}
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void moo(string fileName){
freopen((fileName+".in").c_str(),"r",stdin);
freopen((fileName+".out").c_str(),"w",stdout);
}
#define tc \
int tttttt/*,subtask*/; \
cin >> tttttt/* >> subtask*/; \
while (tttttt--)/*end
*/
int n;
int a[(int)1e5+3];
ll mod = 1e9 + 7;
vector<int>occurences[(int)1e5 + 3];
map<int,int>dp[(int)1e5+3];
int rec(int idx, int si){
if(idx == n || si == n)
return 1;
auto& ref = dp[idx][si];
if(ref)return ref;
auto it = upper_bound(occurences[si].begin(),occurences[si].end(), idx);
auto it2 = upper_bound(occurences[si + 1].begin(), occurences[si + 1].end(), idx);
ll ret = 1;
if(it != occurences[si].end()){
ret += rec(*it, si);
if(ret >= mod)ret -= mod;
}
if(it2 != occurences[si + 1].end()){
ret += rec(*it2, si + 1);
if(ret >= mod)ret -= mod;
}
return ref = ret;
}
int main()
{
ACPLS();
cin>>n;
for(int i = 0; i < n; i++){
cin>>a[i];
for(ll x = 1; x * x <= a[i]; x++){
if(a[i] % x == 0){
if(x <= n)occurences[x].push_back(i);
if(a[i] / x <= n && x * x != a[i]){
occurences[a[i] / x].push_back(i);
}
}
}
}
cout<<rec(0, 1);
}