-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuler003.cpp
More file actions
41 lines (37 loc) · 753 Bytes
/
euler003.cpp
File metadata and controls
41 lines (37 loc) · 753 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
// https://www.hackerrank.com/contests/projecteuler/challenges/euler003/problem
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
ll t;
cin >> t;
while(t--)
{
ll n;
cin >> n;
ll ans = -1;
while( n % 2 == 0)
{
ans = 2;
n /= 2;
}
if( n == 1)
cout << ans << endl;
else
{
for(ll i = 3 ; i * i <= n ; i +=2 )
{
while( n % i == 0)
{
ans = i;
n /= i;
}
}
if( n == 1)
cout << ans << endl;
else
cout << n << endl;
}
}
}