Skip to content

Commit ee7cbff

Browse files
authored
Merge pull request #103 from Abhay-S-R/feature/divisor_analysis
Feat: Add solution for Divisor analysis
2 parents 794d7bb + 2f422cb commit ee7cbff

File tree

1 file changed

+77
-2
lines changed

1 file changed

+77
-2
lines changed

7_mathematics/divisor_analysis.cpp

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,89 @@
1-
// Kunal Sharma IIT Jammu
21
#include <bits/stdc++.h>
32
using namespace std;
43

54
typedef long long ll;
5+
#define mod 1000000007
6+
7+
ll aPowBMod(ll base, ll exp)
8+
{
9+
ll res = 1;
10+
base %= mod;
11+
while (exp > 0)
12+
{
13+
if (exp % 2 != 0)
14+
res = (res * base) % mod;
15+
base = (base * base) % mod;
16+
exp /= 2;
17+
}
18+
return res;
19+
}
620

721
int main()
822
{
923
ios::sync_with_stdio(0);
1024
cin.tie(0);
1125
cout.tie(0);
12-
26+
27+
ll n;
28+
cin >> n;
29+
vector<pair<ll, ll>> values(n);
30+
for (int i = 0; i < n; i++)
31+
{
32+
cin >> values[i].first >> values[i].second;
33+
}
34+
35+
ll numOfDivisors = 1;
36+
ll numOfDivisors_exp = 1;
37+
bool is_tao_even = false;
38+
for (auto &pr : values)
39+
{
40+
ll exp = pr.second;
41+
if((exp+1) % 2 == 0) is_tao_even = true;
42+
numOfDivisors = (numOfDivisors * (exp + 1)) % mod;
43+
numOfDivisors_exp = (numOfDivisors_exp * (exp + 1)) % (mod-1);
44+
}
45+
46+
ll sum = 1;
47+
for (auto &[p, e] : values)
48+
{
49+
ll num = (aPowBMod(p, e + 1) - 1 + mod) % mod; // To prevent negative, if aPowBMod(p, e+1) == 0
50+
ll dem_inv = aPowBMod(p - 1, mod - 2);
51+
ll complete = (num * dem_inv) % mod;
52+
sum = (sum * complete) % mod;
53+
}
54+
55+
ll half_tao = 1;
56+
if(is_tao_even){
57+
bool flag = false;
58+
for(auto &pr : values){
59+
ll exp = pr.second;
60+
if(!flag && (exp+1) % 2 ==0){
61+
exp/=2;
62+
flag = true;
63+
}
64+
half_tao = (half_tao * (exp+1)) % (mod-1);
65+
}
66+
}
67+
68+
ll prod = 1;
69+
ll final_exp;
70+
for (auto &[p, e] : values)
71+
{
72+
if (e % 2 == 0)
73+
{
74+
ll e_half =e / 2;
75+
final_exp = (e_half * numOfDivisors_exp) % (mod - 1);
76+
}
77+
else
78+
{
79+
ll e_mod = e % (mod-1);
80+
final_exp = (half_tao * e_mod) % (mod - 1);
81+
}
82+
ll term = aPowBMod(p, final_exp);
83+
prod = (prod * term) % mod;
84+
}
85+
86+
cout<<numOfDivisors<<" "<<sum<<" "<<prod<<'\n';
87+
1388
return 0;
1489
}

0 commit comments

Comments
 (0)