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 ExplicitDim nCount As IntegerPrivate Sub Command1_Click()
Dim N As LongIf Text1 = "" Then
N = 8
Else
N = Val(Text1)
End IfCal_N NEnd SubPrivate Sub Command2_Click()
End
End SubPrivate 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) / 2Command1.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 LongnCount = 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都可以,谢谢帮忙!
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 ExplicitDim nCount As IntegerPrivate Sub Command1_Click()
Dim N As LongIf Text1 = "" Then
N = 8
Else
N = Val(Text1)
End IfCal_N NEnd SubPrivate Sub Command2_Click()
End
End SubPrivate 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) / 2Command1.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 LongnCount = 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都可以,谢谢帮忙!
解决方案 »
- 程序在这里中断ASSERT(::IsWindow(m_hWnd));ASSERT(pWnd != NULL);
- ISAPI与后台服务器进程间通讯问题!!!
- 曾经酒醉鞭名马,生怕情多累美人。继续散分!
- 关于HttpSendRequest
- 怎么在视频显示流上用鼠标画多边形
- 〖官方〗招收候选版主10-40名
- 用VC 6.0 ,SQL Server ,ADO编程,如何对数据库表纪录的一行进行锁定,即在读取后尚未写入新值之前防止其他人再读此字段信息,请指教。
- 如何上控制面板中的 “显示 属性”加入一个自己的标签或按钮
- 怎样将char[200]转换为LPCTSTR???
- 系统服务使用文本框
- 如何实现画图板中的bmp保存?
- 关于字符处理的两个函数请教
#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;
}