题目大意 给定一个数的质因子表达式,要求你计算机它的值,并减一,再对这个值进行质因数分解,输出表达式 题解 预处理一下,线性筛法筛下素数,然后求出值来之后再用筛选出的素数去分解....其实主要就是字符串处理... 代码: #include <stdio.h> #include <string.h> #include <math.h> #define MAXN 10000 ]; ],cnt=; ]; void get_prime() { ; memset(check,fa…
Everybody in the Prime Land is using a prime base number system. In this system, each positive integer x is represented as follows: Let {pi}i=0,1,2,... denote the increasing sequence of all prime numbers. We know that x > 1 can be represented in only…
Description Everybody in the Prime Land is using a prime base number system. In this system, each positive integer x is represented as follows: Let {pi}i=0,1,2,... denote the increasing sequence of all prime numbers. We know that x > 1 can be represe…
题目链接: http://poj.org/problem?id=1365 题目大意: 告诉你一个数的质因数x的全部底数pi和幂ei.输出x-1的质因数的全部底数和幂 解题思路: 这道题不难.可是题意特别不好理解.对于我这样的英文渣的人.愣是一个小时没看明确 关于题意举例说明吧 比如 509 1 59 1 x = 509^1 * 59^1 = 30031 x-1 = 30030 则答案 13 1 11 1 7 1 5 1 3 1 2 1 就是 x-1 = 13^1 * 11^1 * 7^1 * 5…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1695 题目解析: Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y) = k. 题目又说a==c==1,所以就是求[1,b]与[1,d]中gcd等于k的个数,因为若gcd(x,y)==z,那么gcd(x/z,y/z)==1,又因为不是z的倍数的肯定不是,所以不是z的倍数的可以直接去…
1775: 和尚特烦恼1--是不是素数 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 563  Solved: 193 SubmitStatusWeb Board Description 最近和尚因为一件事特烦恼.有一位施主向和尚询问一个正整数是不是素数的问题.你愿意帮助和尚解决这个烦恼吗? Input 输入数据有多组(以EOF结束).每组数据首先输入一个整数n(n<100). 然后有n个正整数.(每个正整数<= 100000). Output…
题意:给出一个偶数(不论正负),求出两个素数a,b,能够满足 a-b=x,素数在1e6以内. 只要用筛选法打出素数表,枚举查询下就行了. 我用set储存素数,然后遍历set里面的元素,查询+x后是否还是素数. 注意,偶数有可能是负数,其实负数就是将它正数时的结果颠倒就行了. 代码: /* * Author: illuz <iilluzen[at]gmail.com> * Blog: http://blog.csdn.net/hcbbt * File: 10.cpp * Create Date:…
题目链接: A. Lala Land and Apple Trees time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala L…
D. Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the…
Prime Land Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3590   Accepted: 1623 Description Everybody in the Prime Land is using a prime base number system. In this system, each positive integer x is represented as follows: Let {pi}i=0,…
算法训练 Torry的困惑(基本型) 时间限制:1.0s   内存限制:512.0MB      问题描述 Torry从小喜爱数学.一天,老师告诉他,像2.3.5.7……这样的数叫做质数.Torry突然想到一个问题,前10.100.1000.10000……个质数的乘积是多少呢?他把这个问题告诉老师.老师愣住了,一时回答不出来.于是Torry求助于会编程的你,请你算出前n个质数的乘积.不过,考虑到你才接触编程不久,Torry只要你算出这个数模上50000的值. 输入格式 仅包含一个正整数n,其中n…
#6303. 水题 内存限制 10 MiB 时间限制:1000 ms 标准输入输出 题目描述 给定正整数 n,kn, kn,k,已知非负整数 xxx 满足 n!modkx=0,求 xmaxx_{max}x​max​​ . 输入格式 本题包含多组数据,请处理至文件末尾. 对于每组数据,共有一行,两个整数,表示 n,kn, kn,k. 输出格式 对于每组数据,输出一行,一个整数,表示 xmaxx_{max}x​max​​. 样例 输入样例 10 2 5000000000000000000 2 500…
给[L,R]区间的每一个数都质因数分解的复杂度可以达到(R-L)logR,真的涨姿势…… 另外,质因数分解有很重要的一点,就是只需要打sqrt(R)以内的素数表就够了……因为超过sqrt(R)的至多只有一个,分解其他的那些剩下的就是了. 果然学习的过程中要精益求精,把时间和空间都尽量降到最低. 此外还有一个很重要的公式.d(i)表示i的因子个数.那么 #include<bits/stdc++.h> using namespace std; typedef long long ll; ; ];…
Prime Gap 这里直接写中文了 Descriptions: 对于一个数n,若n为素数则输出0,否则找到距离n最小的两个素数,一个大于n,一个小于n,输出他们的差(正数) Input 多组输入 每行包含一个数n 若n为0,程序结束 Output 对于每个测试数据,输出一个答案占一行 Sample Input 10 11 27 2 492170 0 Sample Output 4 0 6 0 114 题目链接: https://vjudge.net/problem/UVA-1644 水题,先求…
Highways Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 26516   Accepted: 12136 Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Fl…
题目连接:http://www.spoj.com/problems/CNTPRIME/ #include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #define lson rt<<1,L,mid #define rson rt<<1|1,mid+1,R /* 水题 题意:给出n个初始值,给出两种操作 0 x y v:将[x,y]的数改…
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> #include<iostream> #include<algorithm> using namespace std; //**************************************************************** // Miller_Rabin 算法进…
J - 数论,质因数分解 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description Tomorrow is contest day, Are you all ready?  We have been training for 45 days, and all guys must be tired.But , you are so lucky comparing with m…
2012_p1 质因数分解 (prime.cpp/c/pas) 时间限制: 1 Sec  内存限制: 128 MB提交: 80  解决: 27[提交][状态][讨论版][命题人:外部导入] 题目描述 1.质因数分解 (prime.cpp/c/pas) [问题描述] 已知正整数 n 是两个不同的质数的乘积,试求出较大的那个质数. [输入] 输入文件名为 prime.in. 输入只有一行,包含一个正整数 n. [输出] 输出文件名为 prime.out. 输出只有一行,包含一个正整数 p,即较大的那…
1059 Prime Factors (25 分)   Given any positive integer N, you are supposed to find all of its prime factors, and write them in the format N = p​1​​​k​1​​​​×p​2​​​k​2​​​​×⋯×p​m​​​k​m​​​​. Input Specification: Each input file contains one test case whi…
//****************************************************************// Miller_Rabin 算法进行素数测试//速度快,而且可以判断 <2^63的数//****************************************************************const int S=20;//随机算法判定次数,S越大,判错概率越小 //计算 (a*b)%c.   a,b都是long long的数,直接相乘…
n!质因数分解后P的个数=n/p+n/(p*p)+n/(p*p*p)+......直到n<p*p*p*...*p //主要代码,就这么点东西,数学真是厉害啊!幸亏我早早的就退了数学2333 do { n/=m; w+=n; }while(n);…
http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1356 题意: 给出n个数,问最多能选几个数,使得该集合中的任意两个数中其中一个数不是另一个质数倍. 思路: 二分图的最大独立集. 那么怎么建图呢?我们按照质因数的奇偶性来分成两部分建图,如果两个数是质数倍的关系,那么就连边,最后最大独立集=点数-最大匹配. 对每个数进行质因数分解,存储每个质因数和质因数的总数,比如说P,质因数为x1,x2,x3...接下来…
https://www.luogu.org/problemnew/show/P1072 一开始看了一看居然还想放弃了的. 把 \(x,a_0,a_1,b_0,b_1\) 质因数分解. 例如 \(x=p_1^{\alpha_1}p_2^{\alpha_2}...p_k^{\alpha_k}\) 由gcd的性质,对应指数的最小值,直接得一组方程. 再有lcm的性质,对应指数的最大值,再得一组方程. 设计起来不难但是写起来就慢多bug的. 第一次交70分,原因是质因数分解过慢! 应该一开始记录原本待分…
题目链接: 传送门 Prime Land Time Limit: 1000MS     Memory Limit: 10000K Description Everybody in the Prime Land is using a prime base number system. In this system, each positive integer x is represented as follows: Let {pi}i=0,1,2,... denote the increasing…
NOIP2012junior-P1-质因数分解 时间: 1000ms / 空间: 131072KB [背景] NOIP2012[描述] 已知正整数n 是两个不同的质数的乘积,试求出较大的那个质数. [输入格式] 输入只有一行,包含一个正整数n . [输出格式] 输出只有一行,包含一个正整数p ,即较大的那个质数. [输入] 21 [输出] 7 [数据范围] 对于 60% 的数据 6 ≤ n ≤ 1000对于 100%的数据 6 ≤ n ≤ 2*10^9 [分析] 判断素数完全没有必要,,n是两个…
前置 费马小定理(即若P为质数,则\(A^P\equiv A \pmod{P}\)). 欧几里得算法(GCD). 快速幂,龟速乘. 素性测试 引入 素性测试是OI中一个十分重要的事,在数学毒瘤题中有着举足轻重的地位. 常见的素性测试如下: int check(int N){ for(int i=2;i*i<=N;i++) if(N%i==0)return 0; return 1; } 以上是一个\(O(\sqrt{N})\)的算法,虽然不优,但在绝大多数情况下是可以的. 但是,假如\(N\)的范…
Prime Land Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3211   Accepted: 1473 Description Everybody in the Prime Land is using a prime base number system. In this system, each positive integer x is represented as follows: Let {pi}i=0,…
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive…
dC Loves Number Theory 题目大意:dC 在秒了BZOJ 上所有的数论题后,感觉萌萌哒,想出了这么一道水题,来拯救日益枯竭的水题资源. 给定一个长度为 n的正整数序列A,有q次询问,每次询问一段区间内所有元素乘积的φ(φ(n)代表1~n 中与n互质的数的个数) .由于答案可能很大,所以请对答案 mod 10^6 + 777. (本题强制在线,所有询问操作的l,r都需要 xor上一次询问的答案 lastans,初始时,lastans = 0) 数据范围:1<=N<=50000…