process.stdin.resume();
process.stdin.setEncoding(‘utf8’);
// your code goes here
process.stdin.on(‘data’,data=>{
function rec(data){
for(i=0;i<data;i++){
if(data%i==0){
console.log(i)
}
}
}
rec(data)
})
my time is 0.09 second and the limit is 1 second how is it possible that it is not satisfied i am new to codechef
If your solution runs on the sample test cases, it doesn’t mean that it will run on the tester’s hidden test cases.
Also, please give the link to the problem and the solution.
2 Likes
hi thanks for the attention
this is the link
Thanks for the link, but I’m sorry I’m not familiar with NODEJS.
2 Likes
node.js doesnot matter you can check the logic
Check My Logic
https://www.codechef.com/viewsolution/46642608
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner scin = new Scanner(System.in);
long n = scin.nextLong();
long half_n = Math.round(n/2);
int count = 0;
String x = "";
for (long i=1;i<=half_n;i++){
if(n%i==0){
count++;
x+=i+" ";
}
}
System.out.println(count+1);
System.out.println(x+n);
}
}
Code is in Java
If you can understand Python,
Here’s the code.
from math import sqrt
n = int(input())
arr = []
for i in range(1,int(sqrt(n))+1):
if n%i==0:
arr.append(i)
if i**2!=n:
arr.append(n//i)
arr.sort()
print(len(arr))
print(*arr)
1 Like
There are two potential errors i can find in your code. Consider the following test case:
Sample Input 2:
6
Sample Output 2:
4
1 2 3 6
Your output will be:
1
2
3
Hint: Use Array to store divisors from 1 to N inclusive.
1 Like