help out to solve this ques: problem code DIFACTRS*
** problem solved **
** Thanks for help**
Access denied
What access denied??
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.
Sorry , about that I didn’t knew contest was going on.
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
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;
}
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