欧拉题专栏

欧拉题1

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

1000以下3和5倍数和

//max以下3和5的倍数 和 ,手输入max
//Multiples of 3 and 5
#include<iostream>


using namespace std;

int GetNum(int max);

int main()
{
	int max,num;
	cin>>max;
	num = GetNum(max);
	cout<<num<<endl;
} 

int GetNum(int max)
{
	int index_max3,index_max5,count,i;
	count = 0;
	if((max%3) ==0 )//3倍数的,i的最大索引
		index_max3 = max/3-1;
	else
		index_max3 = max/3;
	if((max%5) == 0 )//5倍数的,i的最大索引
		index_max5 = max/5-1;
	else
		index_max5 = max/5;
	for(i=0;i<index_max3;i++)//count计算3倍数的和
	{
		count = count + (i+1)*3;
	}
	for(i=0;i<index_max5;i++)
	{
		if(((i+1)%3) == 0)//再计算5的倍数,加到count里
			continue;
		else
			count = count+(i+1)*5; 
	}
	return count;
	
} 

输入1000得到结果233168

 

欧拉题2

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

斐波那契数列奇数项的和

//斐波那切数列奇数项和 ,输入最大的数,不超过这个数的奇数项和
#include<iostream>

using namespace std;

int EvenValuedTerms(double max);

int main()
{
	int max;
	int sum;
	cin>>max;
	cout<<EvenValuedTerms(max);
	return 0;
}

int EvenValuedTerms(double max)
{
	const int first=1,second=2;
	int tmp_odd,tmp_even;
	int sum;
	int i;
	tmp_odd = first;
	tmp_even = second;
	sum = tmp_even;
	for(i=0;;i++)
	{
		tmp_odd = tmp_odd+tmp_even;//下面两个数中的奇数项
		cout<<"odd="<<tmp_odd<<endl;
		if(tmp_odd < max) 
		{
			if(tmp_odd%2==0)
				sum += tmp_odd;
			cout<<"sum="<<sum<<endl;
		}
		else
			break;//超出max就跳出
		tmp_even = tmp_odd+tmp_even;//下面两个数中的偶数项
		cout<<"even="<<tmp_even<<endl;
		if(tmp_even < max)
		{
			if(tmp_even%2==0)
				sum += tmp_even;	
			cout<<"sum="<<sum<<endl;
		}
		else
			break;
	} 
	return sum;
}

输入4000000,得到结果4613732

 

欧拉题3

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

数60....的最大素因子

//数max的最大素因子 
#include<iostream>
#include<vector>

using namespace std;

vector<long long> Prime_Factor(long long max);


int main()
{
	long long max;
	cin>>max;
	cout<<"字节数"<<sizeof(max)<<endl;
	vector<long long> PrimeFactor;
	PrimeFactor = Prime_Factor(max);
	vector<long long>::iterator p = PrimeFactor.end()-1;
	cout<<"max="<<*p<<endl;
} 

vector<long long> Prime_Factor(long long max)
{
	long long i,tmp;
	tmp = max;
	vector<long long> PrimeFactor;
	for(i=2;i<=max;i++)//从2开始找到因子,
	{
		if(tmp%i==0)//把数的这个因子全部分解掉
		{
			PrimeFactor.push_back(i);
			cout<<"i="<<i<<endl;
			while(tmp%i==0)
				tmp = tmp/i;
			cout<<"tmp="<<tmp<<endl;
		}
	}
	cout<<"end"<<endl;
	return PrimeFactor;
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
欧拉伯努利试是一类经典的流体力学目,常用于讨论在流体中的连续性、动量守恒和能量守恒等方面的问。使用MATLAB可以方便地求解这类问。 要解决欧拉伯努利试,我们需要使用流体力学的基本原理,即连续性方程、动量守恒和能量守恒方程。我们可以利用MATLAB编写程序,将这些方程转化为数学模型,并求解相关的物理量。 对于欧拉伯努利试,我们常常需要求解的物理量包括流速、压力和液体高度等。在MATLAB中,我们可以利用流体力学的基本原理建立方程组,并使用数值求解方法计算出相关的物理量。 以一个简单的欧拉伯努利试为例,假设流体在一段管道中流动,已知管道的截面积、液体的初始速度和液体的高度等参数。我们可以利用连续性方程、动量守恒和能量守恒方程,通过MATLAB编写程序求解出管道中的流速、压力和液体的高度等参数。 在MATLAB中,我们可以使用数值求解方法(如Euler法、Runge-Kutta法)对欧拉伯努利试进行数值求解。同时,我们还可以利用MATLAB的可视化功能,将求解结果绘制成图形,更直观地展示出物理量的变化规律。 综上所述,欧拉伯努利试是一个典型的流体力学问,在MATLAB中可以方便地使用数值求解方法求解相关的物理量,并利用可视化功能展示求解结果。通过MATLAB的应用,我们可以更深入地理解流体力学的基本原理,同时也可以更直观地展示和分析物理量的变化情况。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值