-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBestDivisor.java
More file actions
43 lines (36 loc) · 885 Bytes
/
BestDivisor.java
File metadata and controls
43 lines (36 loc) · 885 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
42
43
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
public class Solution
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
long s=0;long p=0;long t=0;
long n = in.nextLong();
for(long i=1;i<=n;i++){
if(n%i==0){
long z=i;
while(z!=0){
long r=z%10;
s=s+r;
z=z/10;
}
if(s>t){
t=s;
p=i;
}
else if(s==t){
if(i<p)
p=i;
}
s=0;
}
}
System.out.print(p);
}
}