• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Hug_Sea
博客园    首页    新随笔    联系   管理    订阅  订阅

文章分类 -  数学

1 2 下一页
ZOJ-3665 Yukari's Birthday

摘要:题意:给出生日n,向多层蛋糕插蜡烛,每层插k^i(i=1,2,3....),求r层蛋糕使k*r最小,若多组k*r相同取r最小的,最上面一层可以选择插1根蜡烛。思路:枚举+二分题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3665View Code 1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 #include <cstdlib> 5 #include <cstring> 阅读全文
posted @ 2012-10-16 23:46 Hug_Sea 阅读(224) 评论(0) 推荐(0)
POJ-2773 Happy 2006(容斥版)

摘要:题意:给出,m和k,求第k个与m互质的数。m (1 <= m <= 1000000), K (1 <= K <= 100000000).思路:容斥+二分,很巧妙的方法。题目链接:http://poj.org/problem?id=2773View Code 1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cmath> 5 #include <cstring> 6 #include <string> 阅读全文
posted @ 2012-10-11 19:20 Hug_Sea 阅读(205) 评论(0) 推荐(0)
HDU-2841 Visible Trees

摘要:题意:就是给定一个坐标(n,m),求(1,1)到(n,m)区间内x与y互质的坐标数。思路:利用容斥从2到n,遍历与m互质的个数。题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2841View Code 1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 #include <cstdlib> 5 #include <cstring> 6 #include <string> 7 #include <a 阅读全文
posted @ 2012-10-11 10:56 Hug_Sea 阅读(207) 评论(0) 推荐(0)
POJ-3904 Sky Code

摘要:题意:给出n个数,问找出4个数满足4个数最大公约数为1,最多有多少组。思路:容斥原理,遍历每个数的素因子,奇数个加偶数个减,然后C(n,4)-sum。题目链接:http://poj.org/problem?id=3904View Code 1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 #include <cstdlib> 5 #include <cstring> 6 #include <string> 7 using namespace std 阅读全文
posted @ 2012-10-11 10:41 Hug_Sea 阅读(233) 评论(0) 推荐(0)
HDU-4135 Co-prime

摘要:题意:给定a、b、c,求a到b区间内与c互质的数。思路:通常我们求1~n中与n互质的数的个数都是用欧拉函数! 但如果n比较大或者是求1~m中与n互质的数的个数等等问题,要想时间效率高的话还是用容斥原理!容斥、先对n分解质因数,分别记录每个质因数, 那么所求区间内与某个质因数不互质的个数就是n / r(i),假设r(i)是r的某个质因子假设只有三个质因子, 总的不互质的个数应该为p1+p2+p3-p1*p2-p1*p3-p2*p3+p1*p2*p3, 及容斥原理,可以转向百度百科查看相关内容pi代表n/r(i),即与某个质因子不互质的数的个数 ,当有更多个质因子的时候,可以用状态压缩解决,二进制 阅读全文
posted @ 2012-10-04 11:00 Hug_Sea 阅读(273) 评论(0) 推荐(0)
ZOJ-2836 Number Puzzle

摘要:题意:给出N个数和M,求1到M的数中与给出的N个数有大于1的公共因子的数的个数。思路:算是第一道容斥原理的题吧,1Y、^_^,神搜求最小公倍数奇数个相加、偶数个相减。题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2836View Code 1 #include <cstdio> 2 #include <cmath> 3 #include <cstdlib> 4 #include <cstring> 5 #include <string> 6 #inc 阅读全文
posted @ 2012-10-02 19:01 Hug_Sea 阅读(172) 评论(0) 推荐(0)
POJ-2115 C Looooops

摘要:题意:就是求A+Cx=B(mod 1<<k)(式 1),的最小x的值。思路:虽然脑袋很乱、不过还是水过。式 1可以转化为Cx-2^ky=B-A,然后直接带扩展欧几里得即可。有一个地方需注意,移位的时候1<<k是错的,写成1LL<<k就过了.....题目链接:http://poj.org/problem?id=2115View Code 1 #include <cstdio> 2 #include <cmath> 3 #include <cstdlib> 4 #include <cstring> 5 #inclu 阅读全文
posted @ 2012-08-24 15:54 Hug_Sea 阅读(182) 评论(0) 推荐(0)
POJ-2142 The Balance

摘要:题意:一个家伙有一种天平,这种天平只有两种重量的砝码a和b,现在要称出重量为c的物品,问你至少需要多少a和b,答案需要满足a的数量加上b的数量和最小,并且他们的重量和也要最小。(两个盘都可以放砝码)。思路:扩展欧几里得、然后暴力枚举。题目链接:http://poj.org/problem?id=2142View Code 1 #include <cstdio> 2 #include <cmath> 3 #include <cstdlib> 4 #include <cstring> 5 #include <string> 6 #incl 阅读全文
posted @ 2012-08-18 17:58 Hug_Sea 阅读(212) 评论(0) 推荐(0)
POJ-1061 青蛙的约会

摘要:题意:有两只青蛙,一只在坐标x,另一直在坐标y,青蛙x一次跳跃可以前进m单位距离,青蛙y一次跳跃可以前进n单位的距离,两青蛙都在同一纬度,该纬度长度为L。两只青蛙同方向同时跳啊跳,问你最少跳多少次,它们才可以相遇,如果不能相遇,输出impossble。思路:初识扩展欧几里得~题目链接:http://poj.org/problem?id=1061View Code 1 #include <cstdio> 2 #include <cmath> 3 #include <cstdlib> 4 #include <cstring> 5 #include & 阅读全文
posted @ 2012-08-18 11:32 Hug_Sea 阅读(208) 评论(0) 推荐(0)
FOJ-1753 Another Easy Problem

摘要:题意:求T组组合数C(n,m)的最大公约数。(1<=m<=n<=100000)思路:求出每组组合数的公共素因子,相乘。对于一个数n,从1到n有多少个数包含一个素因子p呢?答案:n/p个,两个p呢,n/p/p个。所以,求N!里包含某素数因子p的个数,就可以这样求。1 while(n>0){2 x+=n/p;3 n/=p;4 }题目链接:http://acm.fzu.edu.cn/problem.php?pid=1753View Code 1 #include <cstdio> 2 #include <cmath> 3 #include <cs 阅读全文
posted @ 2012-08-14 13:25 Hug_Sea 阅读(204) 评论(0) 推荐(0)
POJ-2992 Divisors

摘要:题意:给定n和k,求C(n,k)的所有因子个数。(0 ≤ k ≤ n ≤ 431)思路:显然不能直接求,将C(n,k)化为n!/(k!*(n-k)!),先对431以内进行素数筛选,因为n!的因子个数等于(n-1)!的因子个数加n的因子个数,所以先打表求出阶乘的因子个数,然后就直接求了。题目链接:http://poj.org/problem?id=2992View Code 1 #include <cstdio> 2 #include <cmath> 3 #include <cstdlib> 4 #include <cstring> 5 #incl 阅读全文
posted @ 2012-08-14 09:33 Hug_Sea 阅读(151) 评论(0) 推荐(0)
POJ-1152 An Easy Problem!

摘要:题意:给定一整数R表示N进制数,求最小的N满足R%(N-1)=0.思路:没注意输入的最大值为32KB,RE一次,如下推倒:设输入的是abcd,假设其解是n进制,因为每一位必然小于n,则有 (a*n*n*n + b*n*n + c*n + d)%(n-1)=0则有:( (a*n*n*n)%(n-1)+ (b*n*n)%(n-1)+ (c*n)%(n-1)+ d )%(n-1)=0则有:( (a* (n%(n-1)) *(n%(n-1)) *(n%(n-1)))+ (b* (n%(n-1)) *(n%(n-1)))+ ... 阅读全文
posted @ 2012-08-09 16:47 Hug_Sea 阅读(191) 评论(0) 推荐(0)
POJ-2773 Happy 2006

摘要:题意:给出正数m(1 <= m <= 1000000),求第K (1 <= K <= 100000000)个与m互质的数。思路:与m互质的数每m的欧拉函数个一循环.如6:1 5,7 11,13 17.....所以求出所有小于m的与m互质的数,然后用k mod m的欧拉函数再乘以相应的倍数。题目链接:http://poj.org/problem?id=2773View Code 1 #include <cstdio> 2 #include <cmath> 3 #include <cstdlib> 4 #include <cstri 阅读全文
posted @ 2012-08-09 11:08 Hug_Sea 阅读(156) 评论(0) 推荐(0)
POJ-3090 Visible Lattice Points

摘要:题意:给定N,求0<=x<=N,0<=y<=N范围内,从点(0,0)到点(x,y)画一条线段,不经过任何点的点的总和.思路:就是求小于等于N的所有欧拉函数之和乘2加1.题目链接:http://poj.org/problem?id=3090View Code 1 #include <cstdio> 2 #include <cmath> 3 #include <cstdlib> 4 #include <cstring> 5 #include <string> 6 #include <algorithm> 阅读全文
posted @ 2012-08-07 15:06 Hug_Sea 阅读(135) 评论(0) 推荐(0)
POJ-2478 Farey Sequence

摘要:题意:给定N,求所有小于等于N的a/b,gcd(a,b)=1(a<b).思路:就是求小于等于N的欧拉函数。题目链接:http://poj.org/problem?id=2478View Code 1 #include <cstdio> 2 #include <cmath> 3 #include <cstdlib> 4 #include <cstring> 5 #include <string> 6 #include <algorithm> 7 #include <iostream> 8 using nam 阅读全文
posted @ 2012-08-07 14:31 Hug_Sea 阅读(167) 评论(0) 推荐(0)
POJ-1284 Primitive Roots

摘要:题意:给定奇素数N,求N的原根。思路:定理:奇素数N的原根等于φ(N-1),即直接求N-1的欧拉函数。题目链接:http://poj.org/problem?id=1284View Code 1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <string> 6 #include <algorithm> 7 #include <iostream> 8 using namespac 阅读全文
posted @ 2012-08-07 09:53 Hug_Sea 阅读(184) 评论(0) 推荐(0)
POJ-2429 GCD & LCM Inverse

摘要:题意:给定某两个数GCD和LCM,求相加和最小的这两个数。(GCD和LCM均小雨2^63)。思路:LCM=a*b/GCD,a/GCD*b/GCD*GCD=LCM,a/GCD*b/GCD=LCM/GCD,即先Pollard_rho法对LCM/GCD进行整数分解,然后对其因子进行深搜找出最小的结果。题目链接:http://poj.org/problem?id=2429View Code 1 /*******************Miller_Rabin素数测试&&Pollard_rho整数分解**************************/ 2 #include <c 阅读全文
posted @ 2012-08-06 19:09 Hug_Sea 阅读(1370) 评论(0) 推荐(0)
POJ-1811 Prime Test(Miller_Rabin素数测试&&Pollard_rho整数分解)

摘要:题意:给定一个数N (2 <= N < 254).判断其是否是素数,是输出"Prime",否则输出N的最小质因数。思路:N很大,需要用Miller_Rabin素数测试法和Pollard_rho整数分解法,当模板用了。题目链接:http://poj.org/problem?id=1811View Code 1 /*******************Miller_Rabin素数测试&&Pollard_rho整数分解**************************/ 2 #include <cstdio> 3 #include < 阅读全文
posted @ 2012-08-06 09:42 Hug_Sea 阅读(426) 评论(0) 推荐(0)
ZJUT-1517 Is it a prime ?

摘要:题意:给定一个数n(2<=n<=10^14),判断其是否是素数。思路:n很大,所以要用到Miller_Rabin素数测试法,直接用二分幂一直wrong,超long long范围,所以要用到multi()。题目链接:http://acm.zjut.edu.cn/ShowProblem.aspx?ShowID=1517View Code 1 /*************************Miller_Rabin素数测试(有待改进)*******************************/ 2 #include <cstdio> 3 #include <cm 阅读全文
posted @ 2012-08-04 16:17 Hug_Sea 阅读(179) 评论(0) 推荐(0)
ZOJ-2562 More Divisors

摘要:题意:给定一个n (1 <= n <= 10^16),求小于等于n的最大反素数。反素数(对于任何正整数x,起约数的个数记做g(x).例如g(1)=1,g(6)=4.如果某个正整数x满足:对于任意i(0<i<x),都有g(i)<g(x),则称x为反素数.)。思路:即求小于等于n的约数最多的数,因为一个数的因子数等于它所有素因子幂加1的乘积,要求最大的反素数,则素因子尽可能要少,幂尽可能要多,所以只对前15个素数所能组成的数进行遍历即可。题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=15 阅读全文
posted @ 2012-08-04 11:25 Hug_Sea 阅读(421) 评论(0) 推荐(0)

1 2 下一页
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3