-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathINVDIV - Smallest Inverse Sum of Divisors.cpp
170 lines (118 loc) · 4.81 KB
/
INVDIV - Smallest Inverse Sum of Divisors.cpp
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
/// BISMILLAHIR RAHMANIR RAHEEM
/// ALLAH IS WATCHING ME
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█
/// ALLAH save us from COVID-19.Amin.
/// Every soul shall taste death.
/// Tag ::
/*
---------------------------
#BoycottFrenceProducts
---------------------------
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
/// order_of_key return number of elements less than x.
/// find_by_order return index.
using namespace std;
using namespace __gnu_pbds;
#define MOHAMMAD ios::sync_with_stdio(0);cin.tie(0);
#define all(x) (x).begin(), (x).end()
#define AE cout << fixed << setprecision(10);
#define ld double
/// faster.
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; // 8-direction.......
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[]= {1,-1,0,0}; // 4-direction...........
int dy4[]= {0,0,1,-1};
using ll = long long;
const ll MOD = 998244353 ;
bool check ( ll a , ll b ){
return (a - (b*(a/b))) == 0;
}
typedef tree< int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
//debug
template<typename F,typename S>ostream&operator<<(ostream&os,const pair<F,S>&p){return os<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&v){os<<"{";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<*it;}return os<<"}";}
template<typename T>ostream&operator<<(ostream&os,const set<T>&v){os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<",";os<<*it;}return os<<"]";}
template<typename T>ostream&operator<<(ostream&os,const multiset<T>&v) {os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<*it;}return os<<"]";}
template<typename F,typename S>ostream&operator<<(ostream&os,const map<F,S>&v){os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<it->first<<" = "<<it->second;}return os<<"]";}
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu(){cerr << endl;}
template<typename T>void faltu(T a[],int n){for(int i=0;i<n;++i)cerr<<a[i]<<' ';cerr<<endl;}
template<typename T,typename...hello>void faltu(T arg,const hello&...rest){cerr<<arg<<' ';faltu(rest...);}
//#else
//#define dbg(args...)
/// Modular arithmetic
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); } /// When MOD is prime.
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
//*********************************************** The END **********************************************************************************************************************************
const int N = 1e8 + 1;
const ll INF = 1e18;
const ll limit = (1LL<<64) - 1;
const ld EPS = 1e-6;
const ll K = 1e5 + 1;
/// Global...
int sigma[N] , ans[N];
void sieve ( ){ /// sigma using nloglogn.
fill ( sigma , sigma+N , 1 );
for ( int i = 2 ; i < N ; i++ ){
if ( sigma[i]!=1 ) continue;
for ( int j = i ; j < N ; j+=i ){
int cur = j;
int p = 1;
int multi = 1;
while ( cur % i == 0 ){ /// 1 + p^1 + p^2 + p^3 .... p^n.
cur/=i;
p*=i;
multi+=p;
}
sigma[j]*=multi;
}
}
}
void solve ( ){
int n;
cin >> n;
if ( ans[n] == 0 ) cout << "-1\n";
else cout << ans[n] << "\n";
return;
}
int main()
{
MOHAMMAD
/*
#ifdef OJ
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
*/
sieve( );
for ( int i = 1 ; i < N ; ++i ){
/// dbg ( i , sigma[i] );
if ( sigma[i] < N and ans[sigma[i]] == 0 ){
ans[sigma[i]] = i;
}
}
int t = 1 , tc = 0;
cin >> t;
while ( t-- ){
solve( );
}
}
/*
Explanation:
----------------------------------------------------------------------------------------------------------------
Alhamdulillah
*/