paizaラーニングレベルアップ問題集の「約数の個数」「約数の列挙」をやってみた。

paizaラーニングレベルアップ問題集の「約数の個数」「約数の列挙」をやってみました。
- - -
##### 問題
###### 約数の個数
https://paiza.jp/works/mondai/loop_problems2/loop_problems2__divsor_count
###### 約数の列挙
https://paiza.jp/works/mondai/loop_problems2/loop_problems2__divsor_print
- - -
##### 方針
$i=1,\dots,N$について、$N\\%i=0$ならば$i$は$N$の約数です。
- - -
##### C
###### 約数の個数
```c
#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	int count = 0;
	for (int i = 1; i <= n; i++) if (n % i == 0) count++;
	printf("%d\n", count);
	return 0;
}
```
###### 約数の列挙
```c
#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) if (n % i == 0) printf("%d\n", i);
	return 0;
}
```
- - -
##### C++
###### 約数の個数
```cpp
#include <iostream>
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;
	return 0;
}
```
###### 約数の列挙
```cpp
#include <iostream>
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;
}
```
- - -
##### C#
###### 約数の個数
```cs
using System;

class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		int count = 0;
		for (int i = 1; i <= n; i++) if (n % i == 0) count++;
		Console.WriteLine(count);
	}
}
```
###### 約数の列挙
```cs
using System;

class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		int count = 0;
		for (int i = 1; i <= n; i++) if (n % i == 0) Console.WriteLine(i);
	}
}
```
- - -
##### Go
###### 約数の個数
```go
package main
import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	count := 0
	for i := 1; i <= n; i++ {
		if n % i == 0 {
			count++
		}
	}
	fmt.Println(count)
}
```
###### 約数の列挙
```go
package main
import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 1; i <= n; i++ {
		if n % i == 0 {
			fmt.Println(i)
		}
	}
}
```
- - -
##### Java
###### 約数の個数
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
		int count = 0;
		for (int i = 1; i <= n; i++) if (n % i == 0) count++;
		System.out.println(count);
	}
}
```
###### 約数の列挙
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
		for (int i = 1; i <= n; i++) if (n % i == 0) System.out.println(i);
	}
}
```
- - -
##### JavaScript
###### 約数の個数
```js
const n = Number(require("fs").readFileSync("/dev/stdin", "utf8"));
let count = 0;
for (var i = 1; i <= n; i++) if (n % i === 0) count++;
console.log(count);
```
###### 約数の列挙
```js
const n = Number(require("fs").readFileSync("/dev/stdin", "utf8"));
for (var i = 1; i <= n; i++) if (n % i === 0) console.log(i);
```
- - -
##### Kotlin
###### 約数の個数
```kotlin
fun main() {
	val n = readLine()!!.toInt()
	var count = 0
	for (i in 1..n) if (n % i == 0) count++
	println(count)
}
```
###### 約数の列挙
```kotlin
fun main() {
	val n = readLine()!!.toInt()
	for (i in 1..n) if (n % i == 0) println(i)
}
```
- - -
##### PHP
###### 約数の個数
```php
<?php
	$n = intval(fgets(STDIN));
	$count = 0;
	for ($i = 1; $i <= $n; $i++) if ($n % $i === 0) $count++;
	echo $count, PHP_EOL;
?>
```
###### 約数の列挙
```php
<?php
	$n = intval(fgets(STDIN));
	for ($i = 1; $i <= $n; $i++) if ($n % $i === 0) echo $i, PHP_EOL;
?>
```
- - -
##### Perl
###### 約数の個数
```pl
my $n = int(<STDIN>);
my $count = 0;
for my $i (1..$n) {
	if ($n % $i == 0) {
		$count++;
	}
}
print "$count$/";
```
###### 約数の列挙
```pl
my $n = int(<STDIN>);
for my $i (1..$n) {
	if ($n % $i == 0) {
		print "$i$/";
	}
}
```
- - -
##### Python3
###### 約数の個数
```py
N = int(input())
count = 0
for i in range(1, N + 1):
	if N % i == 0:
		count += 1
print(count)
```
###### 約数の列挙
```py
N = int(input())
for i in range(1, N + 1):
	if N % i == 0:
		print(i)
```
- - -
##### Ruby
###### 約数の個数
```rb
N = gets.to_i
count = 0
(1..N).each do |i|
	if N % i == 0
		count += 1
	end
end
p count
```
###### 約数の列挙
```rb
N = gets.to_i
(1..N).each do |i|
	if N % i == 0
		p i
	end
end
```
- - -
##### Scala
###### 約数の個数
```scala
import scala.io.StdIn._

object Main extends App{
	val n = readInt()
	var count = 0
	for (i <- 1 to n) if (n % i == 0) count += 1
	println(count)
}
```
###### 約数の列挙
```scala
import scala.io.StdIn._

object Main extends App{
	val n = readInt()
	for (i <- 1 to n) if (n % i == 0) println(i)
}
```
- - -
##### Swift
###### 約数の個数
```swift
let n = Int(readLine()!)!
var count = 0
for i in 1...n {
	if n % i == 0 {
		count += 1
	}
}
print(count)
```
###### 約数の列挙
```swift
let n = Int(readLine()!)!
for i in 1...n {
	if n % i == 0 {
		print(i)
	}
}
```