n,k=gets.split.map(&:to_i);s=0;1.upto(k){|i|g=i.gcd(k);m=n/k+(i<=n%k ?1:0);s+=m*i/g+m*(m-1)*k/g/2};p s
100000000 98765
4199787396686968
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!