LA 4270 离散平方根

本文介绍了一个基于扩展欧几里得算法的应用实例,该算法用于求解最大公约数及贝祖等式的特解。通过具体的代码实现,展示了如何解决特定数学问题,并给出了一种寻找满足特定条件整数解的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include<cstdio>
#include<cstring>
#include<algorithm>
typedef long long LL;
using namespace std;
LL X,n,r;
void exgcd(LL a,LL b,LL &d,LL &x,LL &y)
{
	if(b==0)
	{
		d=a;
		x=1;
		y=0;
	}
	else
	{
		exgcd(b,a%b,d,y,x);
		y-=(a/b)*x;
	}
}
LL res[100000],cnt;
void add(LL a,LL b)
{
	LL c=2*r,d,x,y,t;
	exgcd(a,b,d,x,y);
	if(c%d==0)
	{
		x*=c/d,y*=c/d;
		t=a/d;
		for(int i=y%t;i*b-r<n;i+=t)
		if(i*b-r>=0&&(i*b-r)*(i*b-r)%n==X)
		    res[cnt++]=i*b-r;

	}
}
void solve()
{
	cnt=1;
	res[0]=r;
	for(int i=1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			add(i,n/i);
		    add(n/i,i);
		}
	}
	sort(res,res+cnt);
	cnt=unique(res,res+cnt)-res;
	for(int i=0;i<cnt;i++)
	printf(" %lld",res[i]);
	printf("\n");
}
int main()
{
	int t=1;
	while(~scanf("%lld%lld%lld",&X,&n,&r)&&(n+X+r))
	{
		printf("Case %d:",t++);
		solve();
	}
}

import numpy as np import scipy.linalg as la # 已知参数 a = 0.8 # 长度 (m) b = 0.5 # 宽度 (m) h = 0.001 # 厚度 (m) E = 2.1e11 # 弹性模量 (Pa) mu = 0.3 # 泊松比 rho = 7900 # 密度 (kg/m³) # 求解常数 lambda_ = (np.pi ** 2 * E * h ** 4) / (12 * (1 - mu ** 2) * rho * a ** 2 * b ** 2) # 网格设置 nx = 10 # x方向网格数 ny = 6 # y方向网格数 dx = a / (nx + 1) # x方向每个网格的长度 dy = b / (ny + 1) # y方向每个网格的宽度 # 初始化网格 num_nodes = (ny + 2) * (nx + 2) # 网格点总数 A = np.zeros((num_nodes, num_nodes)) # 创建系数矩阵 B = np.zeros(num_nodes) # 创建结果向量 # 构造差分方程 def construct_difference_equation(): for j in range(1, ny + 1): # 遍历y方向 for i in range(1, nx + 1): # 遍历x方向 idx = (j - 1) * (nx + 2) + (i - 1) # 构造方程 A[idx, idx] = 20 - lambda_ if i > 1: # x方向左邻 A[idx, idx - 1] = -8 if i < nx: # x方向右邻 A[idx, idx + 1] = -8 if j > 1: # y方向上邻 A[idx, idx - (nx + 2)] = -8 if j < ny: # y方向下邻 A[idx, idx + (nx + 2)] = -8 if i > 1 and j > 1: # 左上角邻接 A[idx, idx - (nx + 2) - 1] = 2 if i < nx and j > 1: # 右上角邻接 A[idx, idx - (nx + 2) + 1] = 2 if i > 1 and j < ny: # 左下角邻接 A[idx, idx + (nx + 2) - 1] = 2 if i < nx and j < ny: # 右下角邻接 A[idx, idx + (nx + 2) + 1] = 2 B[idx] = 0 # 默认结果为零 return A, B # 求解固有频率 def calculate_natural_frequencies(): A, B = construct_difference_equation() # 计算特征值 eigenvalues, eigenvectors = la.eig(A) # 不需要 b 参数 sorted_eigenvalues = np.sort(np.real(eigenvalues)) # 提取实部并排序 # 过滤负值和接近零的特征值 valid_eigenvalues = sorted_eigenvalues[sorted_eigenvalues > 0] # 计算平方根并输出 frequencies = np.sqrt(valid_eigenvalues) # 固有频率是特征值的平方根 return frequencies # 计算固有频率 frequencies = calculate_natural_frequencies() # 打印前几个固有频率 print("前几个固有频率 (Hz):") print(frequencies[:10]) 修改这个代码
最新发布
03-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值