两个暴力题。。

题目传送: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 (数学)的更多相关文章

  1. UVA 11827 Maximum GCD

    F - Maximum GCD Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Given the ...

  2. UVA 11827 Maximum GCD【GCD,stringstream】

    这题没什么好说的,但是输入较特别,为此还WA了一次... 题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge& ...

  3. UVA 11827 Maximum GCD (输入流)

    题目:传送门 题意:求n个数的最大公约数,暴力不会超时,难点在没有个数控制的输入. 题解:用特殊方法输入. #include <iostream> #include <cmath&g ...

  4. 邝斌带你飞之数论专题--Maximum GCD UVA - 11827

    Given the N integers, you have to find the maximum GCD (greatest common divisor) of every possible p ...

  5. Maximum GCD(UVA 11827)

    Problem:Given the N integers, you have to find the maximum GCD (greatest common divisor) of every po ...

  6. UVA11827 Maximum GCD

    /* UVA11827 Maximum GCD https://vjudge.net/contest/153365#problem/V 数论 gcd 水题,然而读入比较坑 * */ #include ...

  7. uva 10951 - Polynomial GCD(欧几里得)

    题目链接:uva 10951 - Polynomial GCD 题目大意:给出n和两个多项式,求两个多项式在全部操作均模n的情况下最大公约数是多少. 解题思路:欧几里得算法,就是为多项式这个数据类型重 ...

  8. UVa 10827 - Maximum sum on a torus

    题目大意:UVa 108 - Maximum Sum的加强版,求最大子矩阵和,不过矩阵是可以循环的,矩阵到结尾时可以循环到开头.开始听纠结的,想着难道要分情况讨论吗?!就去网上搜,看到可以通过补全进行 ...

  9. Maximum GCD(fgets读入)

    Maximum GCD https://vjudge.net/contest/288520#problem/V Given the N integers, you have to find the m ...

随机推荐

  1. 刷题总结——Human Gene Functions(hdu1080)

    题目: Problem Description It is well known that a human gene can be considered as a sequence, consisti ...

  2. 【CCF】有趣的数 数位dp

    [思路] dp[i][j]表示前i个数为第j种状态,考虑6种状态 0: 出现且仅出现 2 1: 出现且仅出现 2 0 2: 出现且仅出现 2 3 3: 出现且仅出现 2 0 1 4: 出现且仅出现 2 ...

  3. APIO2018 题解

    坑了好久,补一补. 话说我当时去参加 $APIO2018$ 了,不过纯粹打铁…… 我的程序交道人家毛子的网站上, $c++14$ 编译器不停地给我编 $RE$,只记得好像是结构体排序的问题(删掉那个排 ...

  4. 数表(bzoj 3529)

    Description 有一张N×m的数表,其第i行第j列(1 < =i < =礼,1 < =j < =m)的数值为能同时整除i和j的所有自然数之和.给定a,计算数表中不大于a ...

  5. Linux System Programming 学习笔记(四) 高级I/O

    1. Scatter/Gather I/O a single system call  to  read or write data between single data stream and mu ...

  6. windows.open 以post的方式传递参数

    今天看到有篇文章寫到 windows.open 可以post方式傳遞參數,就趕緊照作看看,結果是可行的,感謝撰寫這篇文章的作者~ /** * window.open with post method  ...

  7. Nginx配置https双向认证

    1.      前期的准备工作: 安装openssl和nginx的https模块 cd ~/ mkdir ssl cd ssl mkdir demoCA cd demoCA mkdir newcert ...

  8. 免费CSS鼠标样式代码大全

    原文发布时间为:2008-08-01 -- 来源于本人的百度文章 [由搬家工具导入] http://5211.91.tc/sb.htm

  9. 线程间通过PostMessage通信

    1.查看TMS项目中的相关实例 ::PostMessage(hWnd, WM_USER_MSG_REFRESH_UI, (WPARAM)UMP_REFRESH_MEMBER_INFO, 0); 参考文 ...

  10. win8防火墙配置出站规则禁止QQ访问

    我们知道Windows自带防火墙可以自定义入站出站规则,那么今天我们就通过配置出站规则禁止QQ访问,在2015年少登QQ,多忙工作,登上人生巅峰,赢娶白富美,哈哈 首先,通过控制面板打开防火墙,可以看 ...