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刷题记的更多相关文章

  1. PE刷题记录

    PE刷题记录 PE60 / 20%dif 这道题比较坑爹. 所有可以相连的素数可以构成一张图,建出这张图,在其中找它的大小为5的团.注意上界的估算,大概在1W以内.1W内有1229个素数,处理出这些素 ...

  2. AGC刷题记

    已经刷不了几天了... AGC001 A-BBQ Easy 排个序就过了 B-Mysterious Light 手膜一下,你会发现魔改一下\(gcd\)就行了 C-Shorten Diameter 刚 ...

  3. ctfshow之Web入门刷题记(从89开始,持续更新)

    0x01Web89-99PHP特性payload Web89 include("flag.php"); highlight_file(__FILE__); if(isset($_G ...

  4. Flask+pin

    Flask+SSTI的新火花 记一次buu刷题记和回顾祥云杯被虐出屎的经历.题目:[GYCTF2020]FlaskApp 一 题目初见 朴实无华的页面,一个base64的小程序页面 看到有提示. 我就 ...

  5. Hasse神舟笔记本卡logo解决,刷BIOS方法,教你修复神船

    我的电脑是神舟战神K660E i7 d7的,前两天装Windows10,Ubuntu,MAC OS Mojave,PE 一堆操作,使用bootice重建uefi引导,结果在前几天,我删了一个重复的ue ...

  6. 记华硕小主机装xp并给nokia e7-00 刷机

    前言 事情是这样的,年前给早先收的小e买了触摸外屏.这会儿有空就给它换上了屏幕,然后尝试装app的时候,发现证书有问题. 根据以往使用n73的经验,然后就百度怎么破解证书. 然后我发现,这些东西网上资 ...

  7. OPPO A57 刷机(官方安装包)+完美Root+ 破解主题+屏蔽Root顶部红色框+NV修复

    朋友说她的手机被被人刷后,有许多预装的软件问我能不能处理下,让我装个纯净版. 开机可以看到预装了许多软件,通常想要删除预装软件就必须Root,于是下载刷机精灵,360刷机大师,线刷包之类的软件Root ...

  8. 谷歌pixel手机解BL锁、刷机、破解电信(史上最详细的帖子)

    本文根据网上已有内容进行整理,对每一个步骤都进行了实践,运气爆棚,几乎没有出现什么重大错误,小错误也进行了很好地解决.因此,十分感激那些为折腾google pixel的IT爱好者,为我提供了无穷的帮助 ...

  9. 盲刷bios

    本帖最后由 evayh 于 2011-12-17 13:09 编辑 先看看是否是insyde的bios,如果是的话,可以救回来 insyde BIOS在损坏时,会自动进入CRISIS MODE试图刷回 ...

随机推荐

  1. Hive Metastore

    metastore:实际保存表信息的地方.     包括: 数据库,表的基本信息:权限信息:存储格式信息:                 各种属性信息:                 权限信息: ...

  2. ReactMotion Demo8 分析

    链接 首先通过spring函数Motion的style参数, 传入Motion Component, 计算style的过程: const style = lastPressed === i & ...

  3. HDU4292 Food —— 最大流 + 拆点

    题目链接:https://vjudge.net/problem/HDU-4292 Food Time Limit: 2000/1000 MS (Java/Others)    Memory Limit ...

  4. windows server2012之部署HTTPS安全站点

    现在的互联网越来越重视网络安全方面的内容,像我们日常生活中浏览的网上银行网站等涉及安全的你都会发现有https 的标志出现,在URL前加https://前缀表明是用SSL加密的. 你的电脑与服务器之间 ...

  5. jetty源码剖析

    最近使用jetty自己写了一个web server,现在闲了花了一天的时间看了一jetty的源代码,主要以server的启动为主线,进行了剖析,经过阅读对jetty的源码大赞,写的简洁.清晰,架构也不 ...

  6. VC++配置OpenGL开发环境

    目录 第1章配置    1 第2章核心文件    6 2.1 核心文件    6 2.2 编译时使用核心文件    6 2.3 运行时使用核心文件    7 2.4 依赖关系    7 第3章 AUX ...

  7. iOS 拼音 Swift K3Pinyin

    iOS 系统方法支持直接获取拼音,避免了之前各种第三方引入各种MAP或者资源文件.下面是一个Swift版本的简单示例: // swift 4.0 func pinyin(_ string: Strin ...

  8. Ruby主要方法

         方法定义        def hello(name) ...  end                                                函数名 参数 作用 备 ...

  9. 洛谷 - P1034 - 矩形覆盖 - dfs

    https://www.luogu.org/problemnew/show/P1034 可能是数据太水了瞎搞都可以过. 判断两个平行于坐标轴的矩形相交(含顶点与边相交)的代码一并附上. 记得这里的xy ...

  10. poj3176【简单DP】

    其实就是简单递推对吧~ 贴一发记忆化搜索的- #include <iostream> #include <stdio.h> #include <string.h> ...