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 |
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
Output
#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
Output
#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
Output
#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
Output