HDU 1695 GCD ★(容斥原理+欧拉函数)
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define MID(x,y) ((x+y)>>1)using namespace std;typedef long long LL; //max long long == 9223372036854775807LLLL phi(LL n)
{if (n == 1) return 0;LL i,sum=n;for(i=2; i*i<=n; i++){if(n%i==0){sum = sum / i * (i-1);do{n/=i;}while(n%i==0);}}if(n>1) sum = sum / n * (n - 1);return sum;
}int solve(int r, int n){if (r == 0) return 0;int res = 0;vector p;for (int i = 2; i * i <= n; i ++){if (n % i == 0){p.push_back(i);while(n % i == 0){n /= i;}}if (n == 1) break;}if (n > 1) p.push_back(n);for (int msk = 1; msk < (1 << p.size()); msk ++){int mult = 1, bit = 0;for (int i = 0; i < p.size(); i ++){if (msk & (1 << i)){bit ++;mult *= p[i];}}int cur = r / mult;if (bit % 2 == 1){res += cur;}else{res -= cur;}}return r - res;
}int main(){int t, caseo = 1;cin>>t;while(t --){int a,b,c,d,k;cin>>a>>b>>c>>d>>k;if (k == 0){cout< d){int tmp = d;d = b;b = tmp;}LL ans = 0;for (int i = 1; i <= b; i ++){ans += (LL)solve(d, i) - phi(i);}cout<
转载于:https://www.cnblogs.com/AbandonZHANG/archive/2012/12/02/4113965.html
HDU 1695 GCD ★(容斥原理+欧拉函数)相关推荐
- hdu 4983 Goffi and GCD(欧拉函数)
Problem Description Goffi is doing his math homework and he finds an equality on his text book: gcd( ...
- hdu 1286 找新朋友 (容斥原理 || 欧拉函数)
Problem - 1286 用容斥原理做的代码: 1 #include <cstdio> 2 #include <iostream> 3 #include <algor ...
- HDU 5514 Frogs(欧拉函数+数论YY)
传送门 Frogs Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- hdu 5597GTW likes function(欧拉函数)
题目链接:[hdu 5597] f(n)=sum((-1)^k * 2^(2n-2k) * C(k, 2n-k+1)) 0<=k<=n 这个公式化简之后就是f(x) = x+1 简单证 ...
- hdu (欧拉函数+容斥原理) GCD
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1695 看了别人的方法才会做 参考博客http://blog.csdn.net/shiren_Bod/ar ...
- 求互质数对的两种方法:欧拉函数和容斥原理
1.HDU4135 首先,我们可以先求出1 ~ a - 1内与n互质的数,再求出1 ~ b内与n互质的数.最后利用前缀和算出来即可. #include <iostream> #includ ...
- HDU 1286 找新朋友 (欧拉函数)
找新朋友 http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2§ionid=1&problemid=8 T ...
- 容斥原理与欧拉函数与莫比乌斯函数,狄利克雷卷积与莫比乌斯变换,反演
莫比乌斯函数可以看成是一种被内化了的容斥原理,许多数论上的结论定理根据容斥原理和数学归纳法可以推导出来,但是有关容斥原理的表达式的构造往往并不容易,运气不好很难找到,而莫比乌斯函数则是巧妙的把容斥原理 ...
- hdu 1286( 欧拉函数 )
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1286 数学题真的是有点吃不消了... View Code 1 #include<iostream ...
- 中gcd函数_欧拉函数φ(n)的计算及欧拉定理
1 欧拉函数定义 在数论中,对正整数n,欧拉函数φ(n)是小于或等于n的正整数中与n互质的数的数目.此函数以其首名研究者欧拉命名,它又称为φ函数(由高斯所命名)或是欧拉总计函数(totient fun ...
最新文章
- 软件是计算机什么及相关文档的总称,1冯-诺依曼原理的基本思想是什么.doc
- Python实现基于朴素贝叶斯的垃圾邮件分类 标签: python朴素贝叶斯垃圾邮件分类 2016-04-20 15:09 2750人阅读 评论(1) 收藏 举报 分类: 机器学习(19) 听说
- 计算机网络与影视多媒体技术 南京理工大学,计算机网络多媒体数学库和课件结构设计-计算机仿真论文-计算机论文(8页)-原创力文档...
- 阿里云伯俊软件:强强联合,共建新生态
- 【code】Splay 模板
- C#中实现js中的eval函数功能
- bzoj4503: 两个串
- 使用window.performance对应用性能监测
- Java - 泛型 ( Generic )
- 智能优化算法:蝙蝠算法-附代码
- leetcode答案集锦
- Python在线编辑器推荐
- omv检查硬盘坏道_MHDD磁盘坏道扫描工具使用方法(详细图文教程)
- 上海交通大学教授金耀辉:AI在智慧法院中的应用
- C语言 数据结构 线性循环队列 基本操作代码
- 计算机制图基本知识6,机械制图基础知识
- Android怎么制作圆角矩形,如何在Android UI中绘制圆角矩形?
- cad工具箱详细讲解_筑龙网CAD工具箱使用说明
- git amend如何撤销
- swpuctf 2021
热门文章
- ehcache 在web项目中使用
- Django 403 CSRF token missing or incorrect.
- javamelody 使用
- JavaScript自定义滚动条
- 深度学习课程笔记(十三)深度强化学习 --- 策略梯度方法(Policy Gradient Methods)...
- Identity Server 4 - Hybrid Flow - MVC客户端身份验证
- Node.js 教程第十四篇——Socket.io
- 最新图解 github 修改github地址 用户名
- springboot项目发布到独立的tomcat中运行
- vue+express+mongoose项目构建