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两种访问方式:HiveServer2 和 Hive Client

        老版HiveClient:  要求比较多,需要Hive和Hadoop的jar包,各配置环境.       HiveServer2:   使得与YARN和HDFS的连接从Client中独立出来, ...

  2. React引入,运行

    1.引入 <script src="https://cdn.bootcss.com/react/15.5.4/react.min.js"></script> ...

  3. html5--6-65 布局4-弹性布局

    html5--6-65 布局4-弹性布局 实例 学习要点 掌握传统布局与CSS3新增弹性布局方式的实现和应用 弹性布局(弹性伸缩布局) 事实上它是一种新类型的盒子模型,也有书上称作弹性伸缩盒布局. 比 ...

  4. golang defer使用——资源关闭时候多用

    defer Go语言中有种不错的设计,即延迟(defer)语句,你可以在函数中添加多个defer语句.当函数执行到最后时,这些defer语句会按照逆序执行,最后该函数返回.特别是当你在进行一些打开资源 ...

  5. 关于return

    return ;  相当于执行完跳转url后停止,return无返回值仅作停止作用,是指停止当前方法,是方法的终点 return null ;  代表引用类型的空值

  6. Linux网络编程笔记(修订版)

    我的网络编程笔记, 因为最近又要做Linux下的网络编程,故重新修订, 其中一些内容参考了文末的链接及文章 1.   基本概念 2.   基本接口 2.1.   打开一个socket 2.2.   将 ...

  7. logging日志类

    #! /usr/bin/env python #coding=utf-8 import logging,os class Logger: def __init__(self, path,clevel ...

  8. 018--python 函数参数、变量、前向引用、递归

    目录 一.python函数的定义 二.函数参数 三.全局变量和局部变量 四.前向引用 五.递归 一.python函数的定义 python函数是对程序逻辑进行结构化或过程化的一种方法 1 python中 ...

  9. 网易蜂巢(云计算基础服务)MongoDB服务重磅来袭

    此文已由作者温正湖授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. MongoDB是目前最为流行的NoSQL数据库,在2017年1月新鲜出炉的数据库权威排行榜上,MongoDB ...

  10. 【WEB基础】HTML & CSS 基础入门(3)段落及文本

    写在前面:CSS选择器 网页要显示很多内容,想要为每个内容设置不同的样式,我们就得首先选中要设置样式的内容,CSS选择器就是指明该样式是针对HTML里哪一个元素的.简单的例子,网页上有几段文字,我们想 ...