[暑假集训--数论]poj2115 C Looooops】的更多相关文章

A Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != B; variable += C) statement; I.e., a loop which starts by setting variable to value A and while variable is not equal to B, repeats statement followed…
Everybody knows any number can be combined by the prime number. Now, your task is telling me what position of the largest prime factor. The position of prime 2 is 1, prime 3 is 2, and prime 5 is 3, etc. Specially, LPF(1) = 0.  InputEach line will con…
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by all the numbers in the set. For example, the LCM of 5, 7 and 15 is 105. InputInput will consist of multiple problem instances. The fi…
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…
Given a sequence of consecutive integers n,n+1,n+2,...,m, an anti-prime sequence is a rearrangement of these integers so that each adjacent pair of integers sums to a composite (non-prime) number. For example, if n = 1 and m = 10, one such anti-prime…
A prime number is a counting number (1, 2, 3, ...) that is evenly divisible only by 1 and itself. In this problem you are to write a program that will cut some number of prime numbers from the list of prime numbers between (and including) 1 and N. Yo…
In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the following conjecture: Every even number greater than 4 can be written as the sum of two odd prime numbers. For example: 8 = 3 + 5. Both…
For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 and p2 such that n = p1 + p2 This conjecture has not been proved nor refused yet. No one is sure whether this conjecture actually holds. However, one…
The sequence of n − 1 consecutive composite numbers (positive integers that are not prime and not equal to 1) lying between two successive prime numbers p and p + n is called a prime gap of length n. For example, ‹24, 25, 26, 27, 28› between 23 and 2…
We say that x is a perfect square if, for some integer b, x = b 2. Similarly, x is a perfect cube if, for some integer b, x = b 3. More generally, x is a perfect pth power if, for some integer b, x = b p. Given an integer x you are to determine the l…
Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine. For example, to measure 200mg of aspirin using 300mg weights and 700mg weights, she can put one 700mg weight on the side of the medicine and three 300m…
Two positive integers are said to be relatively prime to each other if the Great Common Divisor (GCD) is 1. For instance, 1, 3, 5, 7, 9...are all relatively prime to 2006. Now your job is easy: for the given integer m, find the K-th element which is…
Description 两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面.它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止.可是它们出发之前忘记了一件很重要的事情,既没有问清楚对方的特征,也没有约定见面的具体位置.不过青蛙们都是很乐观的,它们觉得只要一直朝着某个方向跳下去,总能碰到对方的.但是除非这两只青蛙在同一时间跳到同一点上,不然是永远都不可能碰面的.为了帮助这两只乐观的青蛙,你被要求写一个程序来判断这两只青蛙是否能够碰面,会在什么时候碰面. 我们把这…
Description A game-board consists of N fields placed around a circle. Fields are successively numbered from1 to N clockwise. In some fields there may be obstacles. Player starts on a field marked with number 1. His goal is to reach a given field mark…
day1: 考微观经济学去了…… day2: 一开始就看了看一道题目最短的B题,拍了半小时交了上去wa了 感觉自己一定是自己想错了,于是去拍大家都过的A题,十分钟拍完交上去就A了 然后B题写了一发暴力对跑,感觉跑出来的数据都是对的,然后看看了题目,看是不是自己读题读错了 WTF!输出居然是Case %d,而我写的是Case #%d = =!,改了改输出格式,交上去就AC了,浪费了我好久时间 然后就去做J题了,J题傻逼题,结果卡全场,赛后一看,long long 改成 unsigned long…
poj2115 C Looooops 题意: 对于C的for(i=A ; i!=B ;i +=C)循环语句,问在k位存储系统中循环几次才会结束. 若在有限次内结束,则输出循环次数. 否则输出死循环. (k位==mod $2^{k}$) 列出方程:$A+Cx\equiv B(mode\quad 2^{k})$ 转换一下:$Cx+ky=B-A$ 用exgcd解出 $Cx+ky=gcd(C,k)$ 然后把求出的$x*(B-A)/gcd(C,k)$ 再$\% (k/gcd(C,k))$求个最小正整数解…
快速全排列的函数 头文件<algorithm> next_permutation(a,a+n) ---------------------------------------------------------------------------------------------------------------------------------------------------------1 - string 与 字符串 find 搜寻失败会返回 string::npos 的值 st…
这又是个状压dp (大型自闭现场) 题目大意: 在N*N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共8个格子. 输入格式: 只有一行,包含两个数N,K . 输出格式: 所得的方案数. 算法分析: 1.显然这又是一道状压的题 2.显然一样是用f数组表示方案数 But 这个f数组需要开三维 为什么呢 我们首先分析一下f的转移情况 f的状态与什么有关呢 首先我们很容易知道我们的dp是从上往下一点点递推实现的 而这个…
题目大意: 如何把一个正整数N(N长度<20)划分为M(M>=1)个部分,使这M个部分的乘积最大.N.M从键盘输入,输出最大值及一种划分方式. 输入格式: 第一行一个正整数T(T<=10000),表示有T组数据. 接下来T行每行两个正整数N,M. 输出格式 对于每组数据 第一行输出最大值. 第二行输出划分方案,将N按顺序分成M个数输出,两个数之间用空格格开. 算法分析: 第一问求dp值就是简单的dp 具体实现可参见 暑假集训day1 水题 乘法最大 1.做第一问的时候注意这个题给出的M并…
题目链接. 分析: 数论了解的还不算太多,解的时候,碰到了不小的麻烦. 设答案为x,n = (1<<k), 则 (A+C*x) % n == B 即 (A+C*x) ≡ B (mod n) 化简得 C*x ≡ (B-A) (mod n) 设 a = C, b = (B-A) 则原式变为 ax=b.解 x. 到这里,以为求出来 a 的逆, 然后 x = b*a-1. a 的 逆好求,用<训练指南>上的模板(P122) inv函数. 例如,求 2 模 66536 下的逆, inv(2,…
题目链接:http://acm.hust.edu.cn/vjudge/contest/125308#problem/G 题意:求有多少x(1<=x<=n),使得gcd(x,n)>=m;     先求n的所有大于等于m的因子, 刚开始用了模拟,超时,看了下往上的题解,说要用到欧拉函数求解,就看了下欧拉函数,  ans=∑phi[n/ei];phi[i]为欧拉函数,为不大于i且与i互质的正整数个数 对于一个与ei互质且小于等于n/ei的正整数p来说,p*ei<=n,gcd(p*ei,n…
题目链接:http://acm.hust.edu.cn/vjudge/contest/125308#problem/F 题意:狼捉兔子,兔子躲在n个洞中一个,这n个洞围成一个圈,狼会从第0号洞开始,搜索隔m的洞,一直搜索下去,问是否存在洞另狼永远搜索不到,这样兔子就重获新生. 刚开始没有思路,就瞎画了八个洞的图,然后m从1—7去找 发现只要 m能够整除n 就能活 也就是是求输入的两个数是否互质即最大公约数是否为1.为1不能活AC代码: import java.io.BufferedReader;…
这个题目,如果没找到方向,确实有点一头雾水.但是如果你找对方向了,AC是分分钟的事.答案就是看n和m是否有除1之外的公约数. 简单证明:设n和m最大公约数不是1,假设为p.n和m总可以化为一个数乘以k的形式吧,不妨令n=a*k,m=b*k(暂时不知道有什么用); 那么狼第一次遍历的洞口编号为0,m,2m......(假设这些洞的编号都在n-1以内),假设狼第i次进洞会超过n-1,则此时本应该是i*m,但是i*m>n-1,所以这次洞口的编号是(i*m)%n,但是,但是,但是(i*m)%n=i*b*…
题意概括:那天以后,你好说歹说,都快炼成三寸不烂之舍之际,小A总算不在摆着死人脸,鼓着死鱼眼.有了点恢复的征兆.可孟子这家伙说的话还是有点道理,那什么天将降....额,总之,由于贤者法阵未完成,而小A又迟迟不现身,FFF团团长连下七道圣火令追杀你们,最先赶到地,机械化部队,它们除了智能不高外,可以说是无懈可击.这正是你要利用的一点,利用他们的行动轨迹,躲藏起来. 问题分析:首先用辗转相除法求得gcd(n,m),若n>m 则gcd(n,m)为一可逃反之,非一可逃. #include "cst…
C Looooops DescriptionA Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != B; variable += C) statement;I.e., a loop which starts by setting variable to value A and while variable is not equal to B, repea…
回想起这个暑假,从开始与雄鹰一起的纠结要不要进集训队,与吉吉博博组队参加地大邀请赛,害怕进不了集训队.当时激励我月份开始接触的,记得当时在弄运动会来着,然后就问了雄鹰一些输入输出的东西,怀着满心的期待参加了寒假集训队但是由于宿舍问题只弄了几天.2.自己的专业基础学的很差,学这个也想给自己培养点兴趣,不想跟以前一样看见代码头就晕掉了.3.浩哥还有健哥他们在去年都集训过,我也想尝试一下. BME集训队选拔赛以第一的成绩进入了集训队,不过8086和PI派了峰峰和明爷solo.从刚开始在板房集训,那时一…
%dalao 今天又有dalao来讲课,讲的是网络流 网络流--从入门到放弃:7-29dalao讲课笔记--https://hzoi-mafia.github.io/2017/07/29/27/   果然是从入门到放弃啊,dalao本来说好下午继续讲完的,然后--就没有然后了 重要的是,mdzz PPT上的板子是假的啊,我找了一下午正经的板子啊,本以为ljm给了个正经板子,没想到是个假的啊,好不容易准备用stdafx的权限号交一下权限题,结果: stdafx, 很抱歉的通知您,您今天的提交次数已…
归来 今天就这样回来了,虽然心里极其不想回来(暑假!@#的只有一天啊喂),但还是回来了,没办法,虽然不喜欢这个地方,但是机房却也是少数能给我安慰的地方,心再累,也没有办法了,不如好好集训= = %dalao 今天下午AntiLeaf大佬给我们讲了一下午的呢~据说明天大佬还要给我们讲,好激动~,话说一直以来都认为叶子是个学姐- -,然而一看讲课的幻灯片,根本想不到他就是叶子啊喂- - 不过大佬讲题的确是可以的,我终于知道,写着个数学式子让你求的不一定是数学题= = みらい(未来) 未来这十来天,我…
莞中OI集训游记 Written BY Jum Leon. I        又是一载夏,本蒟蒻以特长生考入莞中,怀着忐忑的心情到了8月,是集训之际.怀着对算法学习的向往心情被大佬暴虐的一丝恐惧来到了莞中. 这里真是个好地方啊,座居莞城中央,聚集四方灵气.伙食好,我们学习自然好.(廖老师超级友好的 正文 II 感悟 首先感觉在莞中学习真的十分幸运,这里学习的环境.氛围都很好.我们可以互相帮助,互相帮忙讲解不理解的题目,或是分享自己的方法.有廖老师带我们飞(强,组织我们讲解题目,重点难点廖老师会亲…
C Looooops Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 24355   Accepted: 6788 Description A Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != B; variable += C) statement; I.e., a loop w…