多的不说,2点: 1. 暴力不行,用多项式的和,不然超时是必需的; 公式: (a+1+a+d)*d/2 = sum = a*d + (d+1)*d/22. PE,注意"a blank line". AC code:
1#include<stdio.h> 2#include <iostream> 3#include <cmath> 4#include <algorithm> 5using namespace std; 6int n, m; 7int main() 8{ 9 int flag = 0; 10 while(scanf("%d %d", &n, &m) && (n||m)) 11 { 12 int i; 13 int len = int(sqrt(m*2.0)); 14 for(i=len; i>=1; --i) 15 { 16 int temp = m-(i*i+i)/2; 17 if(temp%i == 0) //这里的temp==a*i,所以只要mod成功 18 printf("[%d,%d]\n", temp/i+1, temp/i+i); 19 } 20 printf("\n"); 21 } 22 return 0; 23}
|