ソースを参照

连续自然数和

liuhuan 5 年 前
コミット
a7db7378dc
1 ファイル変更24 行追加0 行削除
  1. 24 0
      A.cpp

+ 24 - 0
A.cpp

@@ -0,0 +1,24 @@
+//
+// Created by liuhuan on 18-11-7.
+//
+#include<bits/stdc++.h>
+using namespace std;
+int main(){
+    int n;
+    while(cin>>n){
+        long long m=2*n;
+        int a=floor(sqrt(m));
+        for(int b=a;b>0;b--){
+            if(m%b)continue;
+            int p=b,q=m/b;
+            int j=(p+q-1)/2;
+            int i=(q-p+1)/2;
+            if(j>i&&i+j==q&&j-i+1==p)
+            {
+                cout<<i<<" "<<j<<endl;
+            }
+        }
+        cout<<endl;
+    }
+    return 0;
+}