欧拉计划 11~20

方阵中的最大乘积
#include <bits/stdc++.h>
using namespace std;

int a[30][30], maxx;

int dx[4] = {0, 1, 1, -1};
int dy[4] = {1, 0, 1, 1};

int main() {
	for (int i = 4; i <= 23; i ++) {
		for (int j = 1; j <= 20; j ++) {
			cin >> a[i][j];
		}
	}

	for (int i = 4; i <= 23; i ++) {
		for (int j = 1; j <= 20; j ++) {
			for (int k = 0; k < 4; k ++) {
				int num = 1;
				for (int l = 0; l < 4; l ++) {
					num *= a[i + dx[k] * l][j + dy[k] * l];
				}
				maxx = max(maxx, num);
			}
		}
	}
	cout << maxx;
	
	return 0;
}
多约数的三角形数
#include <iostream>
using namespace std;

int f(int x) {
	int res = 1;
	
	for (int i = 2; i * i <= x; i ++) {
		int p = 0;	//i ^ p
		while (x % i == 0) {
			x /= i;
			p ++;
		}
		res *= (p + 1);
	}
	if (x > 1) res *= 2;
	return res;
}

int main() {
	for (int i = 1; ; i ++) {
		int x = i * (i + 1) / 2;
		if (f(x) > 500) {
			cout << x;
			return 0;
		}
	}
	
	return 0;
}

/*
质因数分解
x = i1^p1 * i2^p2 * i3^p3 * ......
x的约数个数 = (p1 + 1) * (p2 + 1) * (p3 + 1) * ...... 
*/
大整数的和
#include <bits/stdc++.h>
using namespace std;

vector <int> rd() {
	vector <int> res;
	
	string s;
	cin >> s;
	for (int i = s.size() - 1; i >= 0; i --) res.push_back(s[i] - '0');
	return res;
}

vector <int> add(vector <int> a, vector <int> b) {
	vector <int> res;
	
	int t = 0, len = max(a.size(), b.size());
	for (int i = 0; i < len; i ++) {
		if (i < a.size()) t += a[i];
		if (i < b.size()) t += b[i];
		res.push_back(t % 10);
		t /= 10;
	}
	if (t) res.push_back(t);
	
	return res;
}

int main() {
	vector <int> a, s;

	s.push_back(0);
	for (int i = 1; i <= 100; i ++) {
		a = rd();
		s = add(s, a);
	}
	
	for (int i = s.size() - 1; i >= s.size() - 10; i --) cout << s[i];

	return 0;
}
最长考拉兹序列
#include <bits/stdc++.h>
using namespace std;

int main() {
	int maxx = 0, ans;
	
	for (int i = 1; i <= 1000000; i ++) {
		long long x = i, cnt = 1;
		
		while (x > 1) {
			if (x % 2 == 0) x /= 2;
			else x = x * 3 + 1;
			cnt ++;
		}
		
		if (cnt > maxx) {
			maxx = cnt;
			ans = i;
		}
	}
	
	cout << ans;

	return 0;
}
网格路径
#include <bits/stdc++.h>
using namespace std;

long long f[30];

int main() {
  	int n = 21, m = 21;
  
	f[1] = 1;
	for (int i = 1; i <= n; i ++) {
		for (int j = 1; j <= m; j ++) {
			f[j] += f[j - 1];
		}
	}
	cout << f[m];
	
	return 0;
}
幂的数字和
#include <bits/stdc++.h>
using namespace std;

vector <int> mul(vector <int> a, int x) {
	vector <int> res;
	
	int t = 0;	
	for (int i = 0; i < a.size(); i ++) {
		t += a[i] * x;
		res.push_back(t % 10);
		t /= 10;
	}
	while (t) res.push_back(t % 10), t /= 10;
	
	return res;	
}

int main() {
	vector <int> a;
	
	a.push_back(1);	
	for (int i = 1; i <= 1000; i ++) a = mul(a, 2);
	
	int ans = 0;
	for (int i = 0; i < a.size(); i ++) ans += a[i];
	cout << ans;

	return 0;
}
用英文写出1到1000的所有数字需要多少个字母?
#include <bits/stdc++.h>
using namespace std;

int a[10] = {0, 3, 3, 5, 4, 4, 3, 5, 5, 4};	//0 ~ 9
int b[10] = {3, 6, 6, 8, 8, 7, 7, 9, 8, 8};	//10~19
int c[10] = {0, 0, 6, 6, 5, 5, 5, 7, 6, 6};	//00~90

int main() {
	int ans = 0, t;
	for (int i = 1; i < 1000; i ++) {
		t = i / 100;
		
		if (t) {				//有百位数 
			ans += a[t] + 7;	//eg: one hundred
			
			if (i % 100 != 0) {	//不是整百 
				ans += 3;		//and
			}	
		}
		
		t = i / 10 % 10;
		if (t == 0) {
			ans += a[i % 10];	//个位数 
		}
		else if (t == 1) {		//10~19
			ans += b[i % 10];	
		}
		else {					//20~99
			ans += c[t];		//十位数 
			ans += a[i % 10];	//个位数 
		}
	}
	
	ans += 11;	//one thousand
	cout << ans;

	return 0;
}
最大路径和 I
#include <bits/stdc++.h>
using namespace std;

int a[20][20], f[20];

int main() {
	for (int i = 1; i <= 15; i ++) {
		for (int j = 1; j <= i; j ++) {
			cin >> a[i][j];
		}
	}
	
	for (int i = 15; i >= 1; i --) {
		for (int j = 1; j <= 15; j ++) {
			f[j] = max(f[j], f[j + 1]) + a[i][j];
		}
	}
	cout << f[1];

	return 0;
}
周日计数
#include <bits/stdc++.h>
using namespace std;

int a[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
//1901年1月1日:周二 

int main() {
	int x = 2, cnt = 0;
	for (int y = 1901; y <= 2000; y ++) {
		if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0) a[2] = 29;
		else a[2] = 28;
		
		for (int m = 1; m <= 12; m ++) {
			if (x == 0) cnt ++;
			
			x = (x + a[m]) % 7;
		}
	}
	cout << cnt;

	return 0;
}
阶乘数字和
#include <bits/stdc++.h>
using namespace std;

vector <int> mul(vector <int> a, int x) {
	vector <int> res;
	
	int t = 0;
	for (int i = 0; i < a.size(); i ++) {
		t += a[i] * x;
		res.push_back(t % 10);
		t /= 10;
	}
	while (t) res.push_back(t % 10), t /= 10;
	
	return res;
}

int main() {
	vector <int> a;
	
	a.push_back(1);
	for (int i = 1; i <= 100; i ++) a = mul(a, i);
	
	int ans = 0;
	for (int i = 0; i < a.size(); i ++) ans += a[i];
	cout << ans;
	
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值