Algorithm


Problem Name: beecrowd | 1157

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1157

Divisors I

 

Adapted by Neilor Tonin, URI Brazil

Timelimit: 1

Read an integer N and compute all its divisors.

 

Input

 

The input file contains an integer value.

 

Output

 

Write all positive divisors of N, one value per line.

 

 

 

Input Sample Output Sample

6

1
2
3
6

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include <bits/stdc++.h>

using namespace std;

int main(){
    int n;
    cin >> n;
    for (int i = 1; i  < = n; i++){
        if (n % i == 0){
            cout << i << endl;
        }
    }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
6

Output

x
+
cmd
1 2 3 6

#2 Code Example with Java Programming

Code - Java Programming


import java.io.IOException;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) throws IOException{
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        for (int i = 1; i  < = n; i++){
            if (n % i == 0){
                System.out.println(i);
            }
        }
    }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
6

Output

x
+
cmd
1 2 3 6

#3 Code Example with Javascript Programming

Code - Javascript Programming


var input = require('fs').readFileSync('/dev/stdin', 'utf-8');
var lines = input.split('\n');

var n = parseInt(lines.shift());

for (var i = 1; i  < = n; i++){
    if (n % i === 0){
        console.log(i);
    }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
6

Output

x
+
cmd
1 2 3 6

#4 Code Example with Python Programming

Code - Python Programming


n = int(input())

for i in range(1, n+1):
    if (n % i == 0):
        print(i)
Copy The Code & Try With Live Editor

Input

x
+
cmd
6

Output

x
+
cmd
1 2 3 6
Advertisements

Demonstration


Previous
#1156 Beecrowd Online Judge Solution 1156 S Sequence II Solution in C++, Java, Js and Python
Next
#1158 Beecrowd Online Judge Solution 1158 Sum of Consecutive Odd Numbers III Solution in C++, Java, Js and Python