算法训练——连续正整数的和
//连续正整数的和 #include<stdio.h> int main(){ int n,i=1,j,sum=0; scanf("%d",&n); while(i < n/2+1){ sum = i; for(j=i+1;j<n;j++){ sum += j; if(sum>=n) break; } if(sum == n) printf("%d %d\n",i,j); i++; } return 0; }
//连续正整数的和 #include<stdio.h> int main(){ int n,i=1,j,sum=0; scanf("%d",&n); while(i < n/2+1){ sum = i; for(j=i+1;j<n;j++){ sum += j; if(sum>=n) break; } if(sum == n) printf("%d %d\n",i,j); i++; } return 0; }