【cf 483 div2 -C】Finite or not?(数论)】的更多相关文章

链接:http://codeforces.com/contest/984/problem/C 题意 三个数p, q, b, 求p/q在b进制下小数点后是否是有限位. 思路 题意转化为是否q|p*b^x,即看b和q有没有相同的质因子.如果用筛选质因子的话1e18的数会超时,所以每次求出b和q的gcd,再让q/gcd,如果q最后是1那么b和q拥有相同质因子,输出Finite,反之Infinite. 附代码: #include <bits/stdc++.h> typedef long long LL…
http://codeforces.com/contest/984/problem/C C. Finite or not time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given several queries. Each query consists of three integers pp, qq and …
cf 442 div2 F. Ann and Books(莫队算法) 题意: \(给出n和k,和a_i,sum_i表示前i个数的和,有q个查询[l,r]\) 每次查询区间\([l,r]内有多少对(i,j)满足l <= i <= j <= r 且 sum[j] - sum[i-1] = k\) 思路: 区间左右端点的挪动对答案的贡献符合加减性质,直接用莫队算法即可 复杂度\(O(n * sqrt(n) * log(maxsum))\) 过高 考虑先离散化预处理出所有位置 将\(log\)去…
You are given several queries. Each query consists of three integers pp, qq and bb. You need to answer whether the result of p/qp/q in notation with base bb is a finite fraction. A fraction in notation with base bb is finite if it contains finite num…
A 水题一道. 题目的大致意思就是:给你两个集合,求集合间有多少数对和是奇数. 题解,开\(4\)个桶后,求一个\(min\)就可以了. #include <bits/stdc++.h> using namespace std; int n, m; int v1[4], v2[4]; int main() { scanf("%d%d", &n, &m); for (int i = 1, x; i <= n; i ++) scanf("%d&q…
差不多半年没打cf,还是一样的菜:不过也没什么,当时是激情,现在已是兴趣了,开心就好. A Sweet Problem 思维,公式推一下过了 B PIN Codes 队友字符串取余过了,结果今天早上一看被hack了. C Everyone is a Winner! 除数是斐波那契数列,好像不行?二分.. D Secret Passwords 待补 E Editor 待补 F Economic Difficulties 待补…
LINK:Drazil Likes Heap 那天打CF的时候 开场A读不懂题 B码了30min才过(当时我怀疑B我写的过于繁琐了. C比B简单多了 随便yy了一个构造发现是对的.D也超级简单 dp了一下就没了. 但是到E就只剩下30min(都怪A B浪费我过多时间. 观察题目中给的一个程序 其维护了一个大根堆且这个程序意思是一个函数 这个函数是指对于这个大根堆上的一个非空节点来说每次会将这个值给删掉继承最大的儿子值 然后递归值最大的儿子值得某个节点没有一个非空儿子(那么这个点的值被删掉为0.…
CF#581 题解 A BowWow and the Timetable 如果不是4幂次方直接看位数除以二向上取整,否则再减一 #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<vector> #include<set> #include<map> using namespace std; #define M…
题目:http://codeforces.com/contest/505/problem/D 题目大意:就是给你一个n个点的图,然后你要在图中加入尽量少的有向边,满足所有要求(x,y),即从x可以走到y 分析: 对于输入的图中,可以发现每个连通块是独立的,中间不用连边就可以,于是考虑单个连通块. 如果某个连通块一共有m个点,那么我们知道,我们至少是要加m-1条边才可以保证形成的图是连通的,但是因为是有向边,所以最后形成的图一定是DAG图,这也就意味着这必须要求对于这个连通块,原图也是DAG图,即…
线段树!!1A 代码如下: #include<iostream> #include<cstdio> #define lson i<<1 #define rson i<<1|1 #define MAX 140000 #define ll __int64 using namespace std; ll a[MAX],s; struct tree { int l,r; ll res; bool flag; }T[*MAX]; //奇数OR,偶数XOR void b…