两个暴力题。。

题目传送: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. Java2WSDL 和 WSDL2Java(Axis)

    原文地址:https://www.ibm.com/developerworks/cn/webservices/ws-axisfaq/ 生成或取得WSDL文件 生成客户端或服务端代码 执行WSDL2Ja ...

  2. 关于scarpy的一些说明

    一  scrapy添加代理 1 内置代理:os.environ. 固定格式,不推荐 os.environ['http_proxy'] = "http://root:woshiniba@192 ...

  3. Linux System Programming 学习笔记(一) 介绍

    1. Linux系统编程的三大基石:系统调用.C语言库.C编译器 系统调用:内核向用户级程序提供服务的唯一接口.在i386中,用户级程序执行软件中断指令 INT n 之后切换至内核空间 用户程序通过寄 ...

  4. 回调函数 typedef bool (*IsUsed)(const string &name,boost::shared_ptr<ShpGeometry> oneGeometry);

    就是指向函数的指针. 回调函数,表示了一个函数的地址,将函数作为参数进行使用.参考百度百科:http://baike.baidu.com/view/414773.htm 常用的大概就是在sort函数中 ...

  5. perfect-scrollbar 轻量级滚动插件

    它是一个轻量级的jquery插件. 需要引入的文件: css: #box { position: absolute; overflow: hidden; height: 200px; width: 2 ...

  6. 初识mysql语句

    操作文件夹(库) 增 create database db1 charset utf8; 查 # 查看当前创建的数据库 show create database db1; # 查看所有的数据库 sho ...

  7. Codeforces 932 A.Palindromic Supersequence (ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined))

    占坑,明天写,想把D补出来一起写.2/20/2018 11:17:00 PM ----------------------------------------------------------我是分 ...

  8. luogu P2746 [USACO5.3]校园网Network of Schools

    题目描述 一些学校连入一个电脑网络.那些学校已订立了协议:每个学校都会给其它的一些学校分发软件(称作“接受学校”).注意即使 B 在 A 学校的分发列表中, A 也不一定在 B 学校的列表中. 你要写 ...

  9. Java---详解方法传值问题

    过程解析: 1.首先执行int[] arr={3,5,6,1,7,9,0},遇到数组先执行等式右边的,{3,5,6,1,7,9,0}会在堆内存中开辟一块空间,分成7小块,下标分别从0~6,先进行系统初 ...

  10. pv,uv

    1.PV PV(page view),即页面浏览量:用户每1次对网站中的每个网页访问均被记录1次.用户对同一页面的多次访问,访问量累计. 2.什么是UV uv(unique visitor),指访问某 ...