Skip to content

Commit 325aef4

Browse files
2 parents 0893ebe + 79de954 commit 325aef4

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Factors Finding | Problem Code: DIFACTRS
2+
You are given a number N and find all the distinct factors of N.
3+
Input:
4+
First-line will contain the number N.
5+
Output:
6+
In the first line print number of distinct factors of N.
7+
In the second line print all distinct factors in ascending order separated by space.
8+
Constraints
9+
1≤N≤106
10+
Sample Input 1:
11+
4
12+
Sample Output 1:
13+
3
14+
1 2 4
15+
Sample Input 2:
16+
6
17+
EXPLANATION:
18+
In the first example, all factors of 4 are 1, 2, 4.
19+
In the second example, all factors of 6 are 1, 2, 3, 6.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main() {
5+
int n;
6+
cin>>n;
7+
int count = 0;
8+
9+
for(int i=1;i<=n;i++)
10+
{
11+
if(n%i==0){
12+
count++;
13+
}
14+
}
15+
cout<<count<<endl;
16+
17+
18+
for(int i=1;i<=n;i++)
19+
{
20+
if(n%i==0){
21+
cout<<i<<" ";
22+
}
23+
}
24+
25+
return 0;
26+
}

0 commit comments

Comments
 (0)