3276. 连续正整数之和

kadxm123

题解加注释:
http://blog.csdn.net/kangyan__/article/details/72666912

woria

n=int(input())
for e in range(n):
x=int(input())
if x==3:sum=1
else:
sum=0
for k in range(2,x//2+1):
if 2x%k==0:
if (2
x/k-k+1)%2==0 and (2x/k-k+1)>0 and (2x/k-k+1)/2!=0:
sum+=1
print(‘Case {0}: {1}’.format(e+1,sum))

Money4

连续整数的和为(A(n+k)+An)(k+1)/2 = x,其中1<k<sqrt(2*x)

#include<bits/stdc++.h>
using namespace std;
int main(){
    int T;
    cin>>T;
    for(int t = 0 ; t < T ; t++){
        int x,y=0;
        cin>>x;
        x *= 2;
        for(int i = 2 ;  i < sqrt(x) ; i++){
            if(x%i==0){
                int k = x/i;
                for(int j = 1;;j++){
                    if((2*j+i-1)==k) {
                        y++;
                        break;
                    }
                    else if((2*j+i-1)>k) break;
                }
            }
        }
        printf("Case %d: %d\n",t+1,y);
    }
}
Commando
#include <bits/stdc++.h>

using namespace std;

int main() {
    int T;
    cin >> T;
    for (int c = 1; c <= T; ++c) {
        int sum, res = 0;
        cin >> sum;
        for (int n = sum - 1; n >= 2; --n) {
            double a = (2 * sum / static_cast<double>(n) - n + 1) / 2;
            if (a > 0 && a == static_cast<int>(a)) ++res;
        }
        printf("Case %d: %d\n", c, res);
    }
}
feathes

include

using namespace std;
const int MAX = 1000001;
long long int tot[MAX];
bool search(int, long long int);
int main(void)
{
for (long long int i = 1; i < MAX; i++)
tot[i] += tot[i - 1] + i;
int cnt;
cin >> cnt;
for (int index = 1; index <= cnt; index++)
{
int ret = 0;
long long int n;
cin >> n;
for (int i = 0; i <= n; i++)
if (search(i - 2, tot[i] - n))
ret++;
cout << “Case ” << index << “: ” << ret << endl;
}
return 0;
}
bool search(int line, long long int tar)
{
int left = 0, right = line;
while (left <= right)
{
int mid = left + (right - left) / 2;
if (tot[mid] == tar)
return true;
else if (tot[mid] < tar)
left = mid + 1;
else if (tot[mid] > tar)
right = mid - 1;
}
return false;
}

你当前正在回复 博客/题目
存在问题!