UVA - 11827 - Maximum GCD,10200 - Prime Time (数学)
两个暴力题。。
题目传送:11827 Maximum GCD
AC代码:
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define INF 0x7fffffff
using namespace std; int a[105]; int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
} int main() {
int T;
scanf("%d", &T);
getchar();
while(T --) {
int cnt = 0;
char s[100005];
gets(s);
int len = strlen(s);
for(int i = 0; i < len; i ++) {
if(s[i] != ' ') {
int tmp = 0;
for(; isdigit(s[i]); i ++) {
tmp = tmp * 10 + s[i] - '0';
}
a[cnt ++] = tmp;
}
} int ans = 0;
for(int i = 0; i < cnt; i ++) {
for(int j = i + 1; j < cnt; j ++) {
ans = max(ans, gcd(a[i], a[j]));
}
} printf("%d\n", ans);
}
return 0;
}
题目传送:10200 Prime Time
AC代码:
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define INF 0x7fffffff
using namespace std; int biao[10005]; bool isPrime(int x) {
if(x == 2 || x == 3) return true;
int m = (int)sqrt(x + 0.5);
for(int i = 2; i <= m; i ++) {
if(x % i == 0) return false;
}
return true;
} void init() {
for(int i = 0; i < 40; i ++) {
biao[i] = 1;
}
for(int i = 40; i < 10005; i ++) {
int t = i * i + i + 41;
if(isPrime(t)) {
biao[i] = 1;
}
else biao[i] = 0;
}
} int main() {
init();
int a, b;
while(scanf("%d %d", &a, &b) != EOF) {
int cnt = 0;
for(int i = a; i <= b; i ++) {
cnt += biao[i];
}
printf("%.2lf\n", (cnt * 1.0) / (b - a + 1) * 100.0 + 1e-6);//注意浮点数误差
}
return 0;
}
UVA - 11827 - Maximum GCD,10200 - Prime Time (数学)的更多相关文章
- UVA 11827 Maximum GCD
F - Maximum GCD Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Given the ...
- UVA 11827 Maximum GCD【GCD,stringstream】
这题没什么好说的,但是输入较特别,为此还WA了一次... 题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge& ...
- UVA 11827 Maximum GCD (输入流)
题目:传送门 题意:求n个数的最大公约数,暴力不会超时,难点在没有个数控制的输入. 题解:用特殊方法输入. #include <iostream> #include <cmath&g ...
- 邝斌带你飞之数论专题--Maximum GCD UVA - 11827
Given the N integers, you have to find the maximum GCD (greatest common divisor) of every possible p ...
- Maximum GCD(UVA 11827)
Problem:Given the N integers, you have to find the maximum GCD (greatest common divisor) of every po ...
- UVA11827 Maximum GCD
/* UVA11827 Maximum GCD https://vjudge.net/contest/153365#problem/V 数论 gcd 水题,然而读入比较坑 * */ #include ...
- uva 10951 - Polynomial GCD(欧几里得)
题目链接:uva 10951 - Polynomial GCD 题目大意:给出n和两个多项式,求两个多项式在全部操作均模n的情况下最大公约数是多少. 解题思路:欧几里得算法,就是为多项式这个数据类型重 ...
- UVa 10827 - Maximum sum on a torus
题目大意:UVa 108 - Maximum Sum的加强版,求最大子矩阵和,不过矩阵是可以循环的,矩阵到结尾时可以循环到开头.开始听纠结的,想着难道要分情况讨论吗?!就去网上搜,看到可以通过补全进行 ...
- Maximum GCD(fgets读入)
Maximum GCD https://vjudge.net/contest/288520#problem/V Given the N integers, you have to find the m ...
随机推荐
- [AHOI2008]逆序对(dp)
小可可和小卡卡想到Y岛上旅游,但是他们不知道Y岛有多远.好在,他们找到一本古老的书,上面是这样说的: 下面是N个正整数,每个都在1~K之间.如果有两个数A和B,A在B左边且A大于B,我们就称这两个数为 ...
- [暑假集训--数论]poj2657 Comfort
Description A game-board consists of N fields placed around a circle. Fields are successively number ...
- cf524C The Art of Dealing with ATM
ATMs of a well-known bank of a small country are arranged so that they can not give any amount of mo ...
- 2015-2016 ACM-ICPC Northeastern European Regional Contest (NEERC 15)
NEERC 15 题解1 题解2 官方题解
- SEO总结(一)
- 一简单c++程序之反汇编
#include<iostream> using namespace std; class point3d; class point2d; class point3d { private: ...
- android 设置app root权限简单方法
vim frameworks/base/core/java/com/android/internal/os/ZygoteConnection.java +709 private static void ...
- Java通过开启线程池实现多线程
计算1..100 和1...200 的和,使用线程池开启两个线程 调用Executors类的newFixedThreadPool方法参数是线程池容纳的线程数量 这里是2 返回的对象是 Executo ...
- HDU 3068 Manacher
题目链接:http://hdu.hustoj.com/showproblem.php?pid=3068 今天学习一下马拉车算法,虽然mg讲过,但是没有系统去学. 算法学习:参考博客 马拉车模板题. # ...
- 我的VIM
我的vim 压缩包地址:https://pan.baidu.com/s/1bo1kt8j