072 Counting fractions.pl 410 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/perl
  2. # Author: Daniel "Trizen" Șuteu
  3. # Date: 15 August 2016
  4. # License: GPLv3
  5. # Website: https://github.com/trizen
  6. # https://projecteuler.net/problem=72
  7. # Runtime: 0.378s
  8. use 5.010;
  9. use strict;
  10. use warnings;
  11. use ntheory qw(euler_phi);
  12. sub count_frac {
  13. my ($n) = @_;
  14. my $sum = 0;
  15. foreach my $k (1 .. $n) {
  16. $sum += euler_phi($k);
  17. }
  18. $sum - 1;
  19. }
  20. say count_frac(1e6);