双指针

#include<algorithm>
#include<iostream>
#include<bitset>
#include<cstdio>

#define int long long

using namespace std;

inline int rd(){
  int ret=0,f=1;char c;
  while(c=getchar(),!isdigit(c))f=c=='-'?-1:1;
  while(isdigit(c))ret=ret*10+c-'0',c=getchar();
  return ret*f;
}

int n;

signed main(){
  n=rd();
  int i=1,j=1,s=1;
  while(i<=j){
    if(i==n)break;
    if(s<n){
      s+=(++j);
      continue;
    }
    if(s>n){
      s-=(i++);
      continue;
    }
    if(s==n){
      if(i==j)continue;
      printf("%lld %lld\n",i,j);
      s-=(i++);
      continue;
    }
  }
  return 0;
}

相关文章:

  • 2021-08-03
  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
  • 2021-10-08
  • 2022-02-11
  • 2022-12-23
猜你喜欢
  • 2022-03-10
  • 2021-06-16
  • 2022-01-01
  • 2022-02-22
  • 2021-05-22
  • 2022-12-23
  • 2021-06-19
相关资源
相似解决方案