Test instructions: give you positive integers n and k, and then calculate the and from I to n k%i;
idea; if n is less than 1000000, the direct violence is calculated, then the case is greater than 1000000, and then in the discussion of the size of N and K, according to the k%i situation, you will find that the rule is multiple arithmetic progression, and then you add these arithmetic progression to the answer.
1#include <cstdio>2#include <cstring>3#include <algorithm>4 #definell Long Long5 using namespacestd;6 7 ll N,k;8 ll Getsum (ll N)9 {Tenll sum=0; One for(LL i=1; i<=n; i++) A { -sum+=k%i; - } the returnsum; - } - - intMain () + { - while(SCANF ("%lld%lld", &n,&k)! =EOF) + { A if(n<=1000000) at { -printf"%lld\n", Getsum (n)); - Continue; - } -ll ans=0; -Ans+=max (LL)0, n-k) *K; in for(intI=2; i<=10000; i++) - { to if(i>k) Break; +ll x1=k/(i-1)-k/i; - if(k/i>n)Continue; the ints=k% (k/(i-1)), e=k% (k/i+1); * if(k/(i1) >N) ${s=k%N;Panax Notoginsengx1=n-k/i; - } theans+= (s+e) *x1/2; + } A if(k>10000) the { +ll m=k/10000; -ans+=getsum (m); $ } $printf"%lld\n", ans); - } - return 0; the}
View Code
LA 3521 Joseph ' s problem