-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathSPOJ15555.cc
More file actions
41 lines (35 loc) · 732 Bytes
/
SPOJ15555.cc
File metadata and controls
41 lines (35 loc) · 732 Bytes
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
// SPOJ 15555: Check the coprimeness
// http://www.spoj.com/problems/IITKWPCB/
//
// Solution: math(gcd)
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cstring>
#include <functional>
#include <algorithm>
using namespace std;
#define ALL(c) c.begin(), c.end()
#define FOR(i,c) for(typeof(c.begin())i=c.begin();i!=c.end();++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define fst first
#define snd second
typedef long long LL;
LL gcd(LL a, LL b) {
for (; a; swap(b %= a, a));
return b;
}
LL solve(LL n) {
LL m;
for (m = n/2; m > 0; --m)
if (gcd(m,n) == 1) break;
return m;
}
int main() {
int T; cin >> T;
while (T--) {
LL n; cin >> n;
cout << solve(n) << endl;
}
}