PE刷题记
最喜欢做这种很有意思的数学题了虽然数学很垃圾
但是这个网站的提交方式好鬼畜啊qwq
1.Multiples of 3 and 5
直接枚举
2.Even Fibonacci numbers
直接枚举
3.Largest prime factor
$\sqrt(n)$枚举
#include<cstdio>
#include<vector>
#include<set>
#include<algorithm>
#define sit
#define LL long long
using namespace std;
const int MAXN = 1e6 + ;
inline int read() {
char c = getchar(); LL x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
LL ans = ;
int main() {
LL out = ;
for(LL i = ; i * i <= ans; i++) {
if(ans % i == ) {
out = max(out, i);
while(ans % i == ) ans /= i;
}
}
printf("%I64d", max(out, ans));
return ;
}
/*
*/
T3
4.Largest palindrome product
暴力枚举
#include<cstdio>
#include<vector>
#include<set>
#include<algorithm>
#define sit
#define LL long long
using namespace std;
const int MAXN = 1e6 + ;
inline int read() {
char c = getchar(); LL x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int ans;
int main() {
int ans = ;
for(int i = ; i <= ; i++) {
for(int j = ; j <= ; j++) {
int x = i * j;
int a[], tot = , flag = ;
while(x) a[++tot] = x % , x /= ;
for(int k = ; k <= tot; k++)
if(a[k] != a[tot - k + ]) {flag = ; break;}
if(flag == ) ans = max(ans, i * j);
}
}
printf("%d", ans);
return ;
}
/*
*/
T4
5.Smallest multiple
这个就比较有意思了。
首先我们吧所有的数质因数分解,取每个质数的最大指数,乘起来
update:woc?好像求个最小公倍数就行了??
#include<cstdio>
#include<algorithm>
using namespace std;
int mx[], prime[] = {, , , , , , , , , , , , , , , , , , , };
void getmax(int x) {
for(int i = ; prime[i] <= x && i <= ; i++) {
int cur = ;
if(x % prime[i] == )
while(x % prime[i] == )
cur++, x /= prime[i];
mx[i] = max(mx[i], cur);
} }
int main() {
int N = ;
for(int i = ; i <= N; i++)
getmax(i);
int ans = ;
for(int i = ; i <= N; i++)
for(int j = ; j <= mx[i]; j++)
ans = ans * prime[i];
printf("%d", ans);
}
T5
6.Sum square difference
直接枚举
#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
int N = ;
int main() {
LL ans = * ;
for(int i = ; i <= N; i++) ans = ans - i * i;
printf("%d", ans);
}
6
7.10001st prime
直接一波线性筛
#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
const int MAXN = 1e6 + ;
int N = 1e6;
int prime[MAXN], vis[MAXN], tot = ;
int main() {
for(int i = ; i <= N; i++) {
if(!vis[i]) prime[++tot] = i;
for(int j = ; j <= tot && i * prime[j] <= N; j++) {
vis[i * prime[j]] = ;
if(!(i % prime[j])) break;
}
}
printf("%d", prime[]);
}
7
2018-07-21 07:37:01
8.Largest product in a series
这题目真鬼畜,首先把所有的数copy到一个txt里
然后暴力枚举就行了
2018-07-21 08:01:17
#include<cstdio>
#include<algorithm>
#include<cstring>
#define LL long long
using namespace std;
int N;
char s[];
int main() {
freopen("a.in", "r", stdin);
scanf("%s", s + );
int N = strlen(s + );
LL ans = ;
for(int i = ; i <= N; i++) {
LL now = ;
for(int j = i; j <= i + && j <= N; j++) {
LL x = s[j] - '';
now = now * x;
}
ans = max(ans, now);
}
printf("%I64d", ans);
}
8
9.Special Pythagorean triplet
大力枚举
#include<cstdio>
#include<algorithm>
#include<cstring>
#define LL long long
using namespace std; int main() {
for(int i = ; i <= ; i++)
for(int j = ; j <= ; j++)
for(int k = ; k <= ; k++) {
if((i * i + j * j == k * k) && (i + j + k == )) {
printf("%d %d %d", i * j * k);
}
}
}
9
10.Summation of primes
大力枚举、、
#include<cstdio>
#include<algorithm>
#include<cstring>
#define LL long long
using namespace std;
const int MAXN = 1e7 + ;
int N = ;
LL prime[MAXN], vis[MAXN], tot;
int main() {
for(int i = ; i <= N; i++) {
if(!vis[i]) prime[++tot] = i;
for(int j = ; j <= tot && i * prime[j] <= N; j++) {
vis[i * prime[j]] = ;
if(!(i % prime[j])) break;
}
}
for(int i = ; i <= tot; i++) prime[i] += prime[i - ];
printf("%I64d", prime[tot]);
}
10
2018-07-21 08:08:50
11.Largest product in a grid
直接枚举,一个小优化:考虑到枚举的对称性,每个点都往同一个方向枚举即可
#include<cstdio>
#include<algorithm>
#include<cstring>
#define LL long long
using namespace std;
const int MAXN = 1e7 + ;
int N = ;
LL a[][];
int main() {
LL ans = ;
for(int i = ; i <= N; i++)
for(int j = ; j <= N; j++)
scanf("%I64d", &a[i][j]);
for(int i = ; i <= N; i++)
for(int j = ; j <= N; j++) {
ans = max(ans, a[i][j] * a[i + ][j] * a[i + ][j] * a[i + ][j]);
ans = max(ans, a[i][j] * a[i + ][j + ] * a[i + ][j + ] * a[i + ][j + ]);
ans = max(ans, a[i][j] * a[i + ][j - ] * a[i + ][j - ] * a[i + ][j - ]);
printf("%I64d\n", ans);
} }
11
2018-07-21 08:17:13
12.Highly divisible triangular number
不会做,然后暴力枚举了一发过了qwq。
2018-07-21 09:15:32
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define LL long long
#define int long long
using namespace std;
const int MAXN = 1e6 + , INF = 1e9 + ;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int a[MAXN], sum[MAXN];
int prime[MAXN], vis[MAXN], tot = ;
void GetPrime(int N) {
vis[] = ; prime[] = ;
for(int i = ; i <= N; i++) {
if(!vis[i]) prime[++tot] = i;
for(int j = ; j <= tot && prime[j] * i <= N; j++) {
vis[i * prime[j]] = ;
if(!i % prime[j]) break;
}
}
}
int pd(int val) {
int ans = ;
for(int i = ; prime[i] <= val; i++) {
if(val % prime[i] == ) {
int now = ;
while(val % prime[i] == ) now++, val /= prime[i];
ans = ans * (now + );
}
}
return ans + (val != );
}
main() {
#ifdef WIN32
//freopen("a.in", "r", stdin);
#endif
GetPrime(1e6 + );
a[] = ;
for(int i = ; i <= ; i++) {
a[i] = a[i - ] + i;
sum[i] = pd(a[i]);
if(sum[i] >= ) {printf("%I64d", a[i]); return ;}
//printf("%d\n", sum[i]); }
return ;
}
12
13.Large sum
直接上高精
2018-07-21 09:56:14
14.Longest Collatz sequence
直接一波记忆化搜索
#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<cstdio>
#include<map>
#define LL long long
using namespace std;
const int MAXN = 1e6 + , INF = 1e9 + ;
LL N = 1e6;
map<LL, LL> val;
int dfs(LL i) {
if(val[i]) return val[i];
if(i & ) val[i] = dfs( * i + ) + ;
else val[i] = dfs(i / ) + ;
return val[i];
}
main() {
//freopen("a.in", "r", stdin);
val[] = ;
int ans = , out = ;
for(int i = ; i <= N; i++) {
int now = dfs(i);
if(now > ans) ans = now, out = i;
}
printf("%d", out);
return ;
}
14
2018-07-21 10:07:51
15.Lattice paths
再一波记忆化搜索。。
#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<cstdio>
#include<map>
#define LL long long
using namespace std;
const int MAXN = 1e6 + , INF = 1e9 + ;
LL N = 1e6;
LL ans[][];
LL dfs(int x, int y) {
if(ans[x][y]) return ans[x][y];
if(x - >= ) ans[x][y] += dfs(x - , y);
if(y - >= ) ans[x][y] += dfs(x, y - );
return ans[x][y];
}
main() {
//freopen("a.in", "r", stdin);
ans[][] = ;
printf("%I64d", dfs(, ));
return ;
}
15
2018-07-21 10:14:35
16.Power digit sum
高精度
#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<cstdio>
#include<map>
#define LL long long
using namespace std;
const int MAXN = 1e6 + , INF = 1e9 + ;
LL N = 1e6;
LL ans[][];
LL dfs(int x, int y) {
if(ans[x][y]) return ans[x][y];
if(x - >= ) ans[x][y] += dfs(x - , y);
if(y - >= ) ans[x][y] += dfs(x, y - );
return ans[x][y];
}
main() {
//freopen("a.in", "r", stdin);
ans[][] = ;
printf("%I64d", dfs(, ));
return ;
}
16
21.Amicable numbers
暴力。。
#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<cstdio>
#include<map>
#define LL long long
using namespace std;
const int MAXN = 1e6 + , INF = 1e9 + ;
int vis[MAXN];
int get(int x) {
int ans = ;
for(int i = ; i < x; i++)
if(x % i == ) ans += i;
return ans;
}
main() {
int ans = , N = ;
for(int i = ; i <= N; i++) {
if(vis[i]) continue;
int x = get(i), y = get(x);
//printf("%d %d %d\n", i, x, y);
if(x <= N && y == i && i != x) ans += i + x, vis[i] = , vis[x] = ;
}
printf("%d", ans);
return ;
}
21
50.Consecutive prime sum
开始以为有单调性,也就是如果长度为$x$的能构成素数,那$x - 1$一定能构成素数
但是这样枚举是错的qwq。比如$18$不是素数,但是$29$是素数
然后把二分改成枚举就过了。。
2018-07-21 09:15:19
#include<cstdio>
#include<algorithm>
#include<cstring>
#define LL long long
using namespace std;
const LL MAXN = 1e6 + ;
LL N = ;
LL prime[MAXN], vis[MAXN], tot = ;
LL ans = ;
LL pd(LL num)
{
if(num==||num==) return ;
if(num%!=&&num%!=) return ;
for(register LL i=;i*i<=num;i+=)
if(num%i==||num%(i+)==)
return ;
return ;
}
int len = ;
bool check(LL num) {
for(LL i = ; i <= tot; i++) {
LL r = prime[i + num - ], l = prime[i - ];
if(r - l > N) return ;
if(pd(r - l) == && (i + num - <= tot) && (r - l <= N) && num > len) {
ans = r - l;
len = num;
return ;
}
}
return ;
}
int main() {
for(LL i = ; i <= N; i++) {
if(!vis[i]) prime[++tot] = i;
for(LL j = ; j <= tot && i * prime[j] <= N; j++) {
vis[i * prime[j]] = ;
if(!(i % prime[j])) break;
}
}
for(LL i = ; i <= tot; i++)
prime[i] += prime[i - ];
for(int i = ; i <= tot; i++)
check(i);
printf("%I64d ", ans);
}
50
PE刷题记的更多相关文章
- PE刷题记录
PE刷题记录 PE60 / 20%dif 这道题比较坑爹. 所有可以相连的素数可以构成一张图,建出这张图,在其中找它的大小为5的团.注意上界的估算,大概在1W以内.1W内有1229个素数,处理出这些素 ...
- AGC刷题记
已经刷不了几天了... AGC001 A-BBQ Easy 排个序就过了 B-Mysterious Light 手膜一下,你会发现魔改一下\(gcd\)就行了 C-Shorten Diameter 刚 ...
- ctfshow之Web入门刷题记(从89开始,持续更新)
0x01Web89-99PHP特性payload Web89 include("flag.php"); highlight_file(__FILE__); if(isset($_G ...
- Flask+pin
Flask+SSTI的新火花 记一次buu刷题记和回顾祥云杯被虐出屎的经历.题目:[GYCTF2020]FlaskApp 一 题目初见 朴实无华的页面,一个base64的小程序页面 看到有提示. 我就 ...
- Hasse神舟笔记本卡logo解决,刷BIOS方法,教你修复神船
我的电脑是神舟战神K660E i7 d7的,前两天装Windows10,Ubuntu,MAC OS Mojave,PE 一堆操作,使用bootice重建uefi引导,结果在前几天,我删了一个重复的ue ...
- 记华硕小主机装xp并给nokia e7-00 刷机
前言 事情是这样的,年前给早先收的小e买了触摸外屏.这会儿有空就给它换上了屏幕,然后尝试装app的时候,发现证书有问题. 根据以往使用n73的经验,然后就百度怎么破解证书. 然后我发现,这些东西网上资 ...
- OPPO A57 刷机(官方安装包)+完美Root+ 破解主题+屏蔽Root顶部红色框+NV修复
朋友说她的手机被被人刷后,有许多预装的软件问我能不能处理下,让我装个纯净版. 开机可以看到预装了许多软件,通常想要删除预装软件就必须Root,于是下载刷机精灵,360刷机大师,线刷包之类的软件Root ...
- 谷歌pixel手机解BL锁、刷机、破解电信(史上最详细的帖子)
本文根据网上已有内容进行整理,对每一个步骤都进行了实践,运气爆棚,几乎没有出现什么重大错误,小错误也进行了很好地解决.因此,十分感激那些为折腾google pixel的IT爱好者,为我提供了无穷的帮助 ...
- 盲刷bios
本帖最后由 evayh 于 2011-12-17 13:09 编辑 先看看是否是insyde的bios,如果是的话,可以救回来 insyde BIOS在损坏时,会自动进入CRISIS MODE试图刷回 ...
随机推荐
- webpack与grunt/glub 的比较
webpack.grunt.glub 都是前端打包的工具: grunt/gulp 的工作方式是:在一个配置文件中,指明对某些文件进行压缩.组合.检查等任务的具体步骤,然后在运行中输入相应的命令. we ...
- 集合框架、泛型、迭代(java基础知识十六)
1.ArrayList存储自定义对象并遍历 此类的 iterator 和 listIterator 方法返回的迭代器是快速失败的:在创建迭代器之后,除非通过迭代器自身的 remove 或 add 方法 ...
- SQL Server2005+、MySQL、Oracle 数据库字典生成工具
之前找的数据库字典生成工具基本上都依赖于 Office Com 组件,在不安装 Office的情况下无法使用.怒,于是自己用C# 写了一个. 特征如下: 一.支持的数据库 MS ...
- html5--6-28 css盒模型4
html5--6-28 css盒模型4 实例 学习要点 了解盒模型 元素内容.内边距.边框 和 外边距 了解盒模型的概念: CSS 盒模型规定了处理元素内容.内边距.边框 和 外边距 的方式. 最内部 ...
- http的安全方法和幂等性
最近在研究http,看到http的安全方法和幂等性部分,不太明白,尤其是"post方法是非幂等的"不理解,进过查资料,找到以下两篇有价值的文章,特转过来! 理解HTTP幂等性 转自 ...
- ubuntu下tesseract 4.0安装及参数使用
tesseract是一个开源的OCR引擎,最初是由惠普公司开发用来作为其平板扫描仪的OCR引擎,2005年惠普将其开源出来,之后google接手负责维护.目前稳定的版本是3.0.4.0版本加入了基 ...
- angularJS ng-if的用法
ng-if主要是用来判断是否显示,也可以做为而者选择其中一个的方法,满足判断条件ng-if="变量名" 显示,否者不显示,也可以用ng-if="!变量名"取反, ...
- web项目中url-pattern改成'/'后,js、css、图片等静态资源(404)无法访问问题解决办法
感谢http://blog.csdn.net/this_super/article/details/7884383的文章 1.增加静态资源url映射 如Tomcat, Jetty, JBoss, Gl ...
- js 排列 组合
<script> //组合 function C(arr, num){ var r=[]; (function f(t,a,n){ if (n==0) return r.push(t); ...
- Centos添加jdk环境变量
假设将jdk解压到/opt/jdk1.8.0_131. echo "export JAVA_HOME=/opt/jdk1.8.0_131" >> /etc/profil ...