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

Re:给个数据把...WA的没想法了!

Posted by heathcliff at 2005-10-20 20:39:17 on Problem 2668
In Reply To:给个数据把...WA的没想法了! Posted by:Kinkoyo at 2005-10-20 19:08:44
更新版本!可是还是WA
#include<iostream>
#include<fstream>
using namespace std;
int main(){
	//ifstream cin("a.in");
	__int64 d,n,sum,j,k;
	int i;
	while(cin>>d>>n){
		if(d==0&&n==0) break;
		sum=0;i=1;
		if(n<100000){
			for(j=1;j<=n;j++){
				if(d%j==0){
					sum+=d/j;
				}
				else {
					sum+=d/j;
					sum+=1;
				}
				//printf("%I64d\n",sum);
			}
			printf("%I64d\n",sum);continue;
		}
		if(d==n){
			sum=1;
			while(n>=100000){
				i=i+1;
				if(d%(i)==0){
					j=d/(i);
				}
				else {
					j=d/(i)+1;
				}
				k=n-1;n=j;
				sum+=i*(k-n+1);
			}
			for(j=1;j<n;j++){
				if(d%j==0){
					sum+=d/j;
				}
				else {
					sum+=d/j;
					sum+=1;
				}
			}
		}
		else if(d>n){
			if(d%n==0){
				sum+=d/n;
			}
			else {
				sum+=d/n+1;
			}
			while(n>=100000){
				i=i+1;
				if(d%(i)==0){
					j=d/(i);
				}
				else {
					j=d/(i)+1;
				}
				k=n-1;n=j;
				sum+=i*(k-n+1);
			}
			for(j=1;j<n;j++){
				if(d%j==0){
					sum+=d/j;
				}
				else {
					sum+=d/j;
					sum+=1;
				}
			}
		}
		else {
			sum+=n-d-1;n=d-1;
			while(n>=100000){
				i=i+1;
				if(d%(i)==0){
					j=d/(i);
				}
				else {
					j=d/(i)+1;
				}
				k=n-1;n=j;
				sum+=i*(k-n+1);
			}
			for(j=1;j<=n;j++){
				if(d%j==0){
					sum+=d/j;
				}
				else {
					sum+=d/j;
					sum+=1;
				}
			}
		}
		printf("%I64d\n",sum);
	}
}

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