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

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

Posted by Kinkoyo at 2005-10-20 19:08:44 on Problem 2668
#include<iostream>
#include<fstream>
using namespace std;
int main(){
	//ifstream cin("a.in");
	//ofstream cout("b.out");
	__int64 d,n,m,sum,j,k;
	int i;
	while(cin>>d>>n){
		if(d==0&&n==0) break;
		m=d;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);continue;
		}
		if(d==n){
			sum=1;
			while(n>=100000){
				i=i+1;
				if(m%(i)==0){
					j=m/(i);
				}
				else {
					j=m/(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){
			while(n>=100000){
				i=i+1;
				if(m%(i)==0){
					j=m/(i);
				}
				else {
					j=m/(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(m%(i)==0){
					j=m/(i);
				}
				else {
					j=m/(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