I am able to find the factors but not getting how to print the count of factors like in Sample output in c++
Question : You are given a number N and find all the distinct factors of N
Input: First-line will contain the number N.
Output: In the first line print number of distinct factors of N. In the second line print all distinct factors in ascending order separated by space.
Constraints 1≤N≤10^6
Sample Input 1:
4
Sample Output 1:
3 //Number of factor
1 2 4 //factors
//My code
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int count =0;
for(int i=1;i<=n;i++){
if(n%i == 0){
count++;
cout<<count<<endl;
cout<<i<<" ";
}
}