AtCoder Beginner Contest 165 was held. I got into that D problem a little, so I would like to review ~~ revenge ~~.
AtCoder Beginner Contest 165 D - Floor Function Difficulty: 505
This theme, floor function Ruby Check input example 1 with Excel teacher. You can see that the cycle is exactly ** 7 **. If you think about it carefully, it is because it is divided by ** 7 **, so if n is b -1 or more, the maximum value that the function f can take, and if it is less than, n is a function (because it is a simple increase). The value assigned to f is the answer.
ruby.rb
a, b, n = gets.split.map(&:to_f)
if n >= b - 1
puts (a - a / b).floor
else
puts ((a * n / b).floor - a * (n / b).floor).floor
end
f.rb
a, b, n = gets.split.map(&:to_f)
I coded gets.split.map (&: to_i)
as usual, so I was impatient because the calculation did not match.
python.py
a, b, n = map(int, input().split())
if n >= b - 1:
print(int(a - a / b))
else:
print(int(a * n / b) - a * int(n / b))
perl.pl
chomp (my ($a, $b, $n) = split / /, <STDIN>);
if ($n >= $b - 1) {
print int($a - $a / $b), "\n";
} else {
print (int($a * $n / $b) - $a * int($n / $b)), "\n";
}
java.java
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = Integer.parseInt(sc.next());
Double b = Double.parseDouble(sc.next());
Double n = Double.parseDouble(sc.next());
sc.close();
if (n >= b - 1) {
System.out.println((int) (a - a / b));
} else {
System.out.println((int) (a * n / b) - a * (int) (n / b));
}
}
}
Ruby | Python | Perl | Java | |
---|---|---|---|---|
Code length | 138 Byte | 129 Byte | 169 Byte | 517 Byte |
Execution time | 53 ms | 23 ms | 2 ms | 102 ms |
memory | 14204 KB | 9016 KB | 4788 KB | 35648 KB |
Recommended Posts