Description
给出正整数n和k,计算j(n, k)=k mod 1 + k mod 2 + k mod 3 + … + k mod n的值,其中k mod i表示k除以i的余数。 例如j(5, 3)=3 mod 1 + 3 mod 2 + 3 mod 3 + 3 mod 4 + 3 mod 5=0+1+0+3+3=7
Input
输入仅一行,包含两个整数n, k。
Output
输出仅一行,即j(n, k)。
Sample Input
5 3
Sample Output
7
HINT
50%的数据满足:1<=n, k<=1000
100%的数据满足:1<=n ,k<=10^9
思路:乱搞
1 /************************************************************** 2 Problem: 1257 3 User: cssystem 4 Language: C++ 5 Result: Accepted 6 Time:8 ms 7 Memory:1284 kb 8 ****************************************************************/ 9 10 #include <cstdio> 11 #include <cmath> 12 #include <iostream> 13 #include <cstdlib> 14 using namespace std; 15 16 int n,k,kk,x=0,y,h; 17 long long t,jian=0,ans,sum; 18 19 void init() 20 { 21 cin>>n>>kk; 22 k=kk; 23 if (n>k) 24 { 25 t=n-k; 26 t*=k; 27 ans+=t; 28 n=k; 29 } 30 } 31 void work() 32 { 33 x=1; 34 y=min(n,k); //y refers to the previous number 35 while (x<sqrt(k)) 36 { 37 x++; 38 h=k/x+1; 39 if (h>n) continue; 40 t=y+h; 41 t*=y-h+1; 42 t/=2; 43 t*=x-1; 44 jian+=t; 45 y=h-1; 46 } 47 sum=n-y; 48 sum*=k; 49 ans+=sum; 50 for (int i=1;i<=y;i++) 51 ans+=k % i; 52 ans-=jian; 53 cout<<ans<<endl; 54 } 55 56 int main () 57 { 58 init(); 59 work(); 60 return 0; 61 }
PS:这是我除了A+B外A的第一道BZOJ的题 ,也在新年第一天,标志着我这一年都要奋战BZOJ了!OI is my GF!