
数学
pat数学题分类
eeeeeeeeethan
这个作者很懒,什么都没留下…
展开
-
7-1 Forever (20分)
“Forever number” is a positive integer A with K digits, satisfying the following constrains:the sum of all the digits of A is m;the sum of all the digits of A+1 is n;the greatest common divisor of m and n is a prime number which is greater than 2.Now原创 2020-07-23 21:52:43 · 199 阅读 · 1 评论 -
7-1 Sexy Primes (20分)
7-1 Sexy Primes (20分)Sexy primes are pairs of primes of the form (p, p+6), so-named since “sex” is the Latin word for “six”. (Quoted from http://mathworld.wolfram.com/SexyPrimes.html)Now given an integer, you are supposed to tell if it is a sexy prime.I原创 2020-07-21 22:03:42 · 2482 阅读 · 0 评论 -
1104 Sum of Number Segments (20分)
注意点:由于用double类型保存十进制数时有舍入误差,数据量较大时误差积累,导致结果出错。题目说到每个数不大于1,可以先将每个数放大100000倍,相当于人为地提高double类型的精度,进而减小了误差;注意res += seq[i] * (n - i) * (i + 1);不可以写成res += (n - i) * (i + 1) * seq[i];,因为数据量为105级别的,于是(n - i) * (i + 1)最多可达1010,而int类型最大约为2×109,已经超出了int的表示范围,结果.原创 2020-07-03 23:03:35 · 184 阅读 · 0 评论 -
1069 The Black Hole of Numbers (20分)
用string完成比较麻烦,要将string转为数组再进行排序,然后再转化为string#include<iostream>#include<algorithm>#include<string>#include<vector>using namespace std;bool cmp(int a, int b) { return a > b;}int getVal(vector<int> s) { int res = ..原创 2020-05-10 22:10:57 · 283 阅读 · 0 评论 -
1088 Rational Arithmetic (20分)
#include<iostream>#include<cmath>#include<string>using namespace std;long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a%b);}string getNu...原创 2020-01-20 15:59:56 · 148 阅读 · 0 评论 -
1081 Rational Sum (20分)
#include<cstdio>long long findMinCommon(int a, int b) { long long i = 2; long long minCommon = 1; while (i <= a && i <= b) { if (a % i == 0 && b % i == 0) { minC...原创 2020-01-18 10:16:24 · 106 阅读 · 0 评论