HDU5812 Distance(枚举 + 分解因子)】的更多相关文章

题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5812 Description In number theory, a prime is a positive integer greater than 1 that has no positive divisors other than 1 and itself. The distance between two positive integers x and y, denoted by…
  Product of digits  For a given non-negative integer number N , find the minimal natural Q such that the product of all digits of Q is equal N . Input The first line of input contains one positive integer number, which is the number of data sets. Ea…
其实这题并不难啊,但是分解因子的细节一定要小心. \(比如样例48,2是因子说明24也是因子,也就是说假如x存在\) \(那么x一定是因子中的最小数乘上最大数\) \(那我们现在去验证x是否存在,先拿x去整除除数表,看看是否所有除数都是x的因子\) \(然后再去判断x的因子个数是不是等于n(确保除数表包含所有因子)\) \(考虑到d_i<=1e6,极端情况下x=1e12(我并不确定这种情况存在)\) \(所以我们不一个一个判断sqrt(x)内的数是否是因子,而是采取短除法\) ll x=zu,n…
http://codeforces.com/problemset/problem/757/B 题意:给出n个数,求一个最大的集合并且这个集合中的元素gcd的结果不等于1. 思路:一开始把素数表打出来,发现有9k+个数,不能暴力枚举.发现O(sqrt(n)*n)似乎可行,就枚举因子,然后出现过的因子就在Hash[]加1,最后枚举素数表里的元素,找出现次数最多的,因为那些数都可以映射在素数表里面.注意最少的ans是1. #include <cstdio> #include <algorith…
分析:怎么看都是超时,但是可以先筛一遍1e6以内的每个数的最小素数 算出每个数由多少个素数组成,然后应用,c[1e6][20] 就是题解的那一套,参照题解,比赛的时候没有想到好的办法筛一个数的因子,醉了 然后赛后发现,预处理因子肯定超时,虽然是O(nlogn)的,但是n是1e6啊,常数太大 而且单组操作只有5e4,所以暴力sqrt(x)即可 #include <iostream> #include <vector> #include <queue> #include &…
The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b),is the largest divisor common to a and b,For example,(1,2)=1,(12,18)=6. (a,b) can be easily found by the Euclidean algorithm. Now Carp is considering a litt…
757B - Bash's Big Day 思路:筛法.将所有因子个数求出,答案就是最大的因子个数,注意全为1的特殊情况. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back ; }; int main() { ios::sync_with_stdio(false); cin.tie(); int n,a; cin>>n; ;i<n;i++) {…
思路:打表可以看出是卡特兰数,但是模数不一定是素数,所以需要分解一下因数. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define pii pair<int, int> using namespace std; ; ; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3…
Problem about GCD Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 470    Accepted Submission(s): 77 Problem Description Given integer m. Find multiplication of all 1<=a<=m such gcd(a, m)=1 (cop…
长度为l的用k种字符组成的字符串有k^l中 当中m个字符要不同样 那就是k^l*C(l, m)*(k-1)^m 有反复 要除以2 可是你mod n了 不能直接除 n不一定是素数 所以不能乘以逆元 所以我都mod 2倍的n 最后的结果再除以2 特判l = 1 和 m = 0的情况 #include <cstdio> #include <cstring> #include <cmath> using namespace std; typedef long long LL;…