|
9鱼币
这是我学校上的一道编程题
下面是我的代码
- #include<stdio.h>
- #include<math.h>
- void createRealDivisors(int n){
- int nRoot= (int)sqrt(2*n),a[nRoot],i,count = -1;
- for( i = 2; i <= nRoot;i++){
- if(!(2*n%i)){
- printOutcome(i,2*n/i);
- a[++count] = i;
- }
- }
- if (!(2*n - a[count] * a[count]))
- count--;
- for(i = count;i >= 0;i--)
- printOutcome(2*n / a[i],a[i]);
- }
- void printOutcome(int a,int b){
- if(a%2 ^ b%2 && a+1-b >= 0){
- int left = (a+1-b) / 2;
- int right = left + b - 1;
- printf("%d %d\n",left,right);
- }
- }
- int main(){
- int n;
- scanf("%d",&n);
- createRealDivisors(n);
- return 0;
- }
复制代码
我是用等差算出中差 再用个数算出第一项和最后一项
以为对了 但是提交上去还是错了
错了就改 关键是学校网不给看错在哪 俺很难受
我陷入我的思维很难找到我错的地方
大佬们,求助啊
#include<bits/stdc++.h>
using namespace std;
int m;
int main(){
cin>>m;
for(int k1=sqrt(2*m);k1>1;k1--)//枚举k1(注意是k1>1而不是k1>=1)
if(2*m%k1==0 && (k1+2*m/k1)%2){//如果K2是整数而且与K1一奇一偶
int k2=2*m/k1;
cout<<(k2-k1+1)/2<<" "<<(k1+k2-1)/2<<endl;//输出答案
}
return 0;
}
|
-
最佳答案
查看完整内容
#include
using namespace std;
int m;
int main(){
cin>>m;
for(int k1=sqrt(2*m);k1>1;k1--)//枚举k1(注意是k1>1而不是k1>=1)
if(2*m%k1==0 && (k1+2*m/k1)%2){//如果K2是整数而且与K1一奇一偶
int k2=2*m/k1;
cout
|