Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为啥别人也这样的算法就ac了

Posted by first at 2006-04-03 00:14:46 on Problem 2800
In Reply To:这样怎么也tle不能理解了 Posted by:first at 2006-04-02 21:51:46
> #include <iostream>
> using namespace std;
> 
> int k;
> __int64 mod_sum(int n)
> {
> 	int d = k/n;
> 	int t1 = n;
> 	int t2 = k/(d + 1);
> 	int s, e;
> 	__int64 sum = 0;
> 	while(t1 - t2 > 10)
> 	{
> 		s = k%t1;
> 		e = k%(t2 + 1);
> 		sum +=  __int64(s + e)*(t1 - t2)/2;
> 		d ++;
>                   t1 = t2;
> 		t2 = k/(d + 1);
> 	}
> 	int i;
> 	for(i = 2; i <= t1; i ++)
> 		sum += k%i;
> 	return sum;
> }
> int  main()
> {
>    int n;
>    scanf("%d %d", &n, &k);
>    __int64 sum = 0;
>    if(n == 1)
> 	   sum = 0;
>    else if(k == 1)
> 	   sum = n - 1;
>    else
>    { 
> 	   if(n <= k)
> 		   sum = mod_sum(n);
> 	   else
> 	   {
> 		   sum = mod_sum(k);
> 		   sum += __int64(k)*(n - k);
> 	   }
>    }
>    printf("%I64d\n", sum);
>    return 0;   
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator