Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
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: