Problem solved

help out to solve this ques: problem code DIFACTRS*
** problem solved **
** Thanks for help**

You can check this

Access denied

What access denied??

@dontcheckme Since the contest is going on, we can’t share our solutions I guess.

Just traverse from 1 to n and check whether it is divisible by n or not, if yes increment the counter and insert the element into the list. At the end, print the counter and elements in the list. It’s the naive solution, still it can be optimized, but for the given constraints this solution works.

1 Like

Sorry , about that I didn’t knew contest was going on.

1 Like

the contest is still going on hence can’t check out others solution

I’m also on the same track. Thanks for concreting the path :grinning:

1 Like

int n = sc.nextInt();
for(int i =1 ;i<=n;i++){
if(n%i==0){
System.out.print(i + " ");
}
giving wrong answers. couldn’t find out

Try this!
might help you
try{
n=scan.nextInt();
int arr[]=new int[n];
for(int i=1;i<=n;i++){
if(n%i==0){
arr[count]=i;
count++;
}
}
System.out.println(count);
for(int i=0;i<count;i++){
System.out.print(arr[i]+" ");
}
}
catch(Exception e){
return;
}

1 Like

same with me.

Did I use the right method

Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();//input
		
		//variables
		int count =0;
		int divisor = 1;
		int quotient = N;
		
		// List of Factors
		List<Integer> list = new ArrayList<Integer>();
		
		//Finding factor 
		while(divisor<=quotient){
			if(quotient*divisor == N && N != 1 && N !=0 && quotient != divisor){
				count += 2;
				list.add(divisor);
				list.add(quotient);
				//System.out.println(divisor+" " + quotient);
			}
			else if (N ==1 || N == 0 && divisor*quotient==N){
				list.add(quotient);
				count +=1;
				//System.out.println(divisor+" ");
			}
			else if(divisor== quotient && divisor*quotient==N){
				list.add(divisor);
				count+=1;
				//System.out.println(divisor+" ");
			}
			divisor+=1;
			quotient = N/divisor;
			
		}
		Collections.sort(list);
		//Printing short list
		System.out.println(count);
		for(int i = 0;i<list.size();i++){
			System.out.print(list.get(i)+" ");
		}

points to check

1.are you printing the count??
2.chck for edge case (in this case chck for input 1)
3. are you triming your final string