Click here to Skip to main content
15,890,741 members

Comments by Jahirul Sarker (Top 37 by date)

Jahirul Sarker 9-Feb-23 20:38pm View    
I edited in "What have you tried" section.
Jahirul Sarker 9-Feb-23 19:48pm View    
Thank you. But still TLE.
Last submitted solution:
```
//package pac1;
import java.util.Scanner;
public class Main{

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt();
int k = sc.nextInt();
int sum=0;
int top = (int)Math.sqrt(n);
for(int i=1; i<=top; i++) {
if(n%i==0 ){
if(i%k!=0)sum+=i;
if((n/i)%k!=0)sum+=(n/i);
}
}
System.out.println(sum);
}

}
}
```
Jahirul Sarker 9-Feb-23 5:13am View    
I searched in Google for the solution of this problem in Java, but found no results. A user asked on this same issue in UVA discussion site.. but no reply has been given.

I don't know how to solve this problem by maintaining a list of prime numbers.
Jahirul Sarker 9-Feb-23 4:40am View    
"your optimized solution is flawed: it adds twice to the sum the square root of N." I edited the mistake.
I submitted your solution. But still getting TLE. @CPallini
Jahirul Sarker 3-Jan-23 11:52am View    
It worked. I was really worried and kept submitting with little little change but couldn't figure out the problem. Your solution saved me. Thank you so much.