CodeChef GCD2
GCD2Problem code: GCD2
|
All submissions for this problem are available.
Frank explained its friend Felman the algorithm of Euclides to calculate the GCD
of two numbers. Then Felman implements it algorithm
int gcd(int a, int b)
{
if (b==0)
return a;
else
return gcd(b,a%b);
}
and it proposes to Frank that makes it
but with a little integer and another integer that has up to 250 digits.
Your task is to help Frank programming an efficient code for the challenge of Felman.
Input
The first line of the input file contains a number representing the number of lines to follow.
Each line consists of two number A and B (0 <= A <= 40000 and A <= B < 10^250).
Output
Print for each pair (A,B) in the input one integer representing the GCD of A and B.
Example
Input:
2
2 6
10 11 Output:
2
1
求一个大数 , 一个<=4W整数的GCD 。。
枚举整数的约数, 模拟大数除法 ,用大数除去这些约数,判一下余数是否为0
#include <bits/stdc++.h> using namespace std;
const int N = ;
int A,BB[N],num[N],tot;
char s[];
vector<int>B;
inline int gcd( int a , int b ) { return b == ? a : gcd(b,a%b); } bool check( int n ) {
int c = ;
for( int i = ; i < B.size() ; ++i ) {
c = c * + B[i];
c %= n ;
}
if( c == ) return true ;
return false;
} void Run() {
scanf("%d %s",&A,s);
tot = ;
int n = strlen(s) ;
if( A == ) { puts(""); return ; }
else if( A == ) { puts(s); return ; }
B.resize(n);
for( int i = ; i < strlen(s) ; ++i ) B[i] = s[i] - '';
for( int i = ; i <= A ; ++i ) if( A % i == ) {
num[tot++] = i ;
}
for( int i = tot- ; i >= ; --i ) if( check(num[i]) ) {
printf("%d\n",num[i]);
return ;
}
}
int main()
{
//freopen("in","r",stdin);
int _ , cas = ;
scanf("%d",&_);
while(_--)Run();
}
CodeChef GCD2的更多相关文章
- scau 2015寒假训练
并不是很正规的.每个人自愿参与自愿退出,马哥找题(马哥超nice么么哒). 放假第一周与放假结束前一周 2015-01-26 http://acm.hust.edu.cn/vjudge/contest ...
- 【BZOJ-3514】Codechef MARCH14 GERALD07加强版 LinkCutTree + 主席树
3514: Codechef MARCH14 GERALD07加强版 Time Limit: 60 Sec Memory Limit: 256 MBSubmit: 1288 Solved: 490 ...
- 【BZOJ4260】 Codechef REBXOR 可持久化Trie
看到异或就去想前缀和(⊙o⊙) 这个就是正反做一遍最大异或和更新答案 最大异或就是很经典的可持久化Trie,从高到低贪心 WA: val&(1<<(base-1))得到的并不直接是 ...
- codechef 两题
前面做了这场比赛,感觉题目不错,放上来. A题目:对于数组A[],求A[U]&A[V]的最大值,因为数据弱,很多人直接排序再俩俩比较就过了. 其实这道题类似百度之星资格赛第三题XOR SUM, ...
- codechef January Challenge 2014 Sereja and Graph
题目链接:http://www.codechef.com/JAN14/problems/SEAGRP [题意] 给n个点,m条边的无向图,判断是否有一种删边方案使得每个点的度恰好为1. [分析] 从结 ...
- BZOJ3509: [CodeChef] COUNTARI
3509: [CodeChef] COUNTARI Time Limit: 40 Sec Memory Limit: 128 MBSubmit: 339 Solved: 85[Submit][St ...
- CodeChef CBAL
题面: https://www.codechef.com/problems/CBAL 题解: 可以发现,我们关心的仅仅是每个字符出现次数的奇偶性,而且字符集大小仅有 26, 所以我们状态压缩,记 a[ ...
- CodeChef FNCS
题面:https://www.codechef.com/problems/FNCS 题解: 我们考虑对 n 个函数进行分块,设块的大小为S. 每个块内我们维护当前其所有函数值的和,以及数组中每个元素对 ...
- codechef Prime Distance On Tree(树分治+FFT)
题目链接:http://www.codechef.com/problems/PRIMEDST/ 题意:给出一棵树,边长度都是1.每次任意取出两个点(u,v),他们之间的长度为素数的概率为多大? 树分治 ...
随机推荐
- GB28181 To RTMP/HLS/HTTP-FLV/DASH Gateway
I. Deployment / Architecture Block Diagram II. Resources Used 1. freeswitch —— sip server https://f ...
- CAS实现SSO单点登录
环境 cas-server-4.1.8,cas-client-3.4.0,Java-8,Maven-3,Tomcat-7.0.72 CAS Server 安装 点此进入 CAS 下载列表,选择下载 c ...
- tac 反向显示文件内容
1.命令功能 tac是cat的反向拼写,功能是反向显示文件内容. 2.语法格式 tac option file 3.使用范例 [root@localhost chu]# cat test.txt ...
- NVMe固态硬盘工具箱使用说明
https://www.bilibili.com/read/cv562989/ 浦科特NVMe固态硬盘工具箱使用说明 数码 2018-6-7 687阅读7点赞3评论 浦科特已经推出针对NVMe固态硬盘 ...
- 怎么实现web端上传超大文件
1.介绍enctype enctype 属性规定发送到服务器之前应该如何对表单数据进行编码. enctype作用是告知服务器请求正文的MIME类型(请求消息头content-type的作用一样) 1. ...
- Android逆向之旅---静态分析技术来破解Apk
一.前言 从这篇文章开始我们开始我们的破解之路,之前的几篇文章中我们是如何讲解怎么加固我们的Apk,防止被别人破解,那么现在我们要开始破解我们的Apk,针对于之前的加密方式采用相对应的破解技术,And ...
- Xenu Link Sleuth 简单好用的链接测试工具
XenuLink Sleuth 名词介绍 “Xenu链接检测侦探”是被广泛使用的死链接检测工具.可以检测到网页中的普通链接.图片.框架.插件.背景.样式表.脚本和java程序中的链接. 那么神马时候出 ...
- bzoj1964: hull 三维凸包
传送门 二维平面四个点求凸包面积->任选三个点面积之和/2 三维平面五个点求凸包体积->任选四个点体积之和/2 二维平面三个点面积->二个二维向量行列式值的绝对值/2 三维平面四个点 ...
- (转)Centos7 yum 源安装nginx
转:https://www.cnblogs.com/fuhai0815/p/8522868.html 一.建立nginx源 vim /etc/yum.repos.d/nginx.repo [nginx ...
- Kubernetes tutorial - K8S 官方入门教程 中文翻译
官方教程,共 6 个小节.每一小节的第一部分是知识讲解,第二部分是在线测试环境的入口. kubectl 的命令手册 原文地址 1 创建集群 1.1 使用 Minikube 创建集群 Kubernete ...