NEU OJ 1649 GMZ’s Pretty Number】的更多相关文章

先来一次线性素数筛,把1到10000000的素数都筛选出来,然后暴力跑一遍所有可能的值,打个表,查询的时候o(1)效率出解. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<queue> #include<cstring> using namespace std; ; },num_prime = ; , }; +]; +];…
循环节是2000000016 字符串读入,用一下高精度对2000000016取个模,用一下快速幂就可以算出答案了. #include <cstdio> #include <iostream> #include<cstring> using namespace std; ; long long mod1(char *a1,int b) { ] = {}; ] = {}; long long i, k, d; k = strlen(a1); ; i < k; i++)…
Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 比较简单,类似进制的转换,代码如下: class Solution { pu…
题目描述: 每个人有自己的lucky number,小A也一样.不过他的lucky number定义不一样.他认为一个序列中某些数出现的次数为n的话,都是他的lucky number.但是,现在这个序列很大,他无法快速找到所有lucky number.既然这样,他就想找到那些不是lucky number. 输入: 输入有两行. 第一行有n和m.n表示出现次数为n的是lucky number,m表示序列的长度.2<=n<=10,m<=10^6,m%n!=0. 第二行为序列元素,每个元素都是…
优先级队列 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<queue> using namespace std; int n; int main() { while(~scanf("%d",&n)) { ; priority_queue<int>Q; while(n--) { int x; sc…
/** 题目:Solve Equation 链接:http://acm.hnust.edu.cn/JudgeOnline/problem.php?id=1643 //最终来源neu oj 2014新生选拔赛题 题意:给定两个数的和以及他们的最小公倍数,求这两个数. 思路: x+y=A lcm(x,y)=B => x*y/gcd(x,y)=B 要把这两个公式联立,那么必须消掉gcd: 设:d = gcd(x,y), x = kx*d, y = ky*d; kx与ky互质: x+y=A => d(…
C - Prime number or not Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice FZU 1649 Description Your task is simple.Give you a number N, you should judge whether N is a prime number or not. Input There…
Problem link: http://oj.leetcode.com/problems/single-number-ii/ The problem seems like the Single Number. Suppose we have following (3m+1) numbers in the array A: x0, x1, x1, x1, ..., xm, xm, xm We are asked to find out the value of x0. However we ca…
Prolbem link: http://oj.leetcode.com/problems/single-number/ This prolbem can be solved by using XOR(exclusive OR) operation. Let x, y, and z be any numbers, and XOR has following properties: x XOR 0 is itself, i.e. x XOR 0 = 0; x XOR x is 0, i.e. x…
[九度OJ]题目1040:Prime Number 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1040 题目描述: Output the k-th prime number. 输入: k≤10000 输出: The k-th prime number. 样例输入: 3 7 样例输出: 5 17 Ways 首先用C++做了一遍,刚开始没有AC的原因是判断素数的函数写的不对,没有处理2这个情况.后来发现每次停止循环的时候…