有点难的问题,我不知道怎么办了

奇伢 2003-06-08 05:00:23
VERSION 5.00
Begin VB.Form Form1
AutoRedraw = -1 'True
BorderStyle = 1 'Fixed Single
Caption = "Form1"
ClientHeight = 3195
ClientLeft = 45
ClientTop = 330
ClientWidth = 4680
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "退出"
Height = 375
Left = 2880
TabIndex = 3
Top = 2760
Width = 855
End
Begin VB.CommandButton Command1
Caption = "计算"
Height = 375
Left = 1560
TabIndex = 2
Top = 2760
Width = 855
End
Begin VB.TextBox Text1
Height = 270
Left = 2040
TabIndex = 1
Top = 1320
Width = 1095
End
Begin VB.Label Label2
AutoSize = -1 'True
Height = 180
Left = 1920
TabIndex = 4
Top = 1800
Width = 90
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "N="
Height = 180
Left = 1800
TabIndex = 0
Top = 1320
Width = 180
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Option Explicit

Dim nCount As Integer

Private Sub Command1_Click()
Dim N As Long

If Text1 = "" Then
N = 8
Else
N = Val(Text1)
End If

Cal_N N

End Sub

Private Sub Command2_Click()
End
End Sub

Private Sub Form_Load()

Form1.Width = 800 * 15
Form1.Height = 600 * 15
Form1.ScaleMode = vbPixels
Form1.Left = (Screen.Width - Form1.Width) / 2
Form1.Top = (Screen.Height - Form1.Height) / 2

Command1.Left = 350
Command1.Top = 500
Command2.Left = 450
Command2.Top = 500
End Sub


Private Sub Cal_N(ByVal N As Long)
Dim i As Long
Dim j As Long
Dim k As Long
Dim X As Long
Dim Y As Long
Dim Z As Long
Dim xRangeMin As Long
Dim xRangeMax As Long
Dim yRangeMin As Long
Dim yRangeMax As Long
Dim Nxy As Long
Dim xy_N As Long

nCount = 0
xRangeMax = N * 3 / 4
xRangeMin = N / 4

For i = xRangeMin To xRangeMax
If N <> 4 * i Then
yRangeMax = i * N / (i + i + i + i - N) * 2
'yRangeMin = i * N / (i + i + i + i - N)

For j = i To yRangeMax
Nxy = N * i * j
xy_N = 4 * i * j - N * i - N * j
If xy_N > 0 Then
` If Nxy Mod xy_N = 0 Then
Open "d:\N=" & N & ".txt" For Append As #1
Print #1, i & " " & j & " " & Nxy / xy_N & Chr(13)
Print i & " " & j & " " & Nxy / xy_N
Close #1
nCount = nCount + 1
End If
End If
Next j
End If
Next i
Label2.Caption = "总共得到" & nCount & "组结果。"
End Sub



我要的是求出4/n=1/x+1/y+1/z的所有的正整数的解,x,y,z之间的排序算一个解,
例如:4/8=1/6+1/6+1/6=1/5+1/10+1/10=1/4+1/8+1/8=.....=....
这个n=8时有10组解;上面的程序我试n=500的时候行,而n=2000的时候会溢出。请高手们,教我怎么改,谢谢!用VB/Vc都可以,谢谢帮忙!
...全文
65 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzqzzq 2003-06-08
  • 打赏
  • 举报
回复
满足x<=y<=z的全部解,可算到2000以上,速度很快。
#include<iostream.h>
void main()
{
int n; cin>>n;
for(int x=1;x<n;x++)
{
int y=x,m=2*x*x;
do{
m=4*x*y-n*x-n*y;
if(m<=0)
{
y++;
m=4*x*y-n*x-n*y;
}
if(m>0 && ((n*x*y)%m)==0)
{
cout<<"("<<x<<","<<y<<","<<(n*x*y)/m<<")"<<" ";
}
y++;
} while(((n*x*y)/m)>=y);
}
cout<<endl;
}
奇伢 2003-06-08
  • 打赏
  • 举报
回复
谢谢 SoLike(是我),我希望有人能给我答案??
思危 2003-06-08
  • 打赏
  • 举报
回复
up
奇伢 2003-06-08
  • 打赏
  • 举报
回复
turboc2写也可以,我很急,明天要给人了!

16,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧