题目链接:

http://www.spoj.com/problems/VLATTICE/

题意:

1≤x,y,z≤n,问有多少对(x,y,z)使得gcd(x,y,z)=1

分析:

欧拉搞不了了,我们用莫比乌斯来搞一搞。

同样,我们设

f(d):满足gcd(x,y,z)=d且x,y,z均在给定范围内的(x,y,z)的对数。

F(d):满足d|gcd(x,y,z)且x,y,z均在给定范围内的(x,y,z)的对数。

显然F(d)=[n/d][n/d][n/d],反演后我们得到

f(x)=∑x|dμ(d/x)[n/d]∗[n/d]∗[n/d]

直接求解f(1)即可。

特别注意坐标轴上的点和坐标平面上的点。

代码:

/*
-- SPOJ 7001
-- mobius
-- Create by jiangyuzhu
-- 2016/5/30
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <stack>
using namespace std;
typedef long long ll;
#define sa(n) scanf("%d", &(n))
#define sal(n) scanf("%I64d", &(n))
#define pl(x) cout << #x << " " << x << endl
#define mdzz cout<<"mdzz"<<endl;
const int maxn = 1e6 + 5 ;
int tot = 0;
int miu[maxn], prime[maxn], f[maxn];
bool flag[maxn];
void mobius()
{
miu[1] = 1;
tot = 0;
for(int i = 2; i < maxn; i++){
if(!flag[i]){
prime[tot++] = i;
miu[i] = -1;
}
for(int j = 0; j < tot && i * prime[j] < maxn; j++){
flag[i * prime[j]] = true;
if(i % prime[j]) miu[i * prime[j]] = -miu[i];
else{
miu[i * prime[j]] = 0;
break;
}
}
}
}
int main (void)
{
mobius();
int T;sa(T);
int n;
for(int kas = 1; kas <= T; kas++){
scanf("%d", &n);
ll ans = 3;
for(int i = 1; i <= n; i++){
ans += miu[i] * 1ll * (n/ i) * (n / i) * (n / i + 3);
}
printf("%lld\n", ans);
}
return 0;
}

最新文章

  1. DEDE后台登录和前台验证码不显示的解决方法
  2. Android 2.x中使用actionbar - Actionbarsherlock (2)
  3. Android百分比布局支持库介绍——com.android.support:percent(转)
  4. Sql Server 调用DLL
  5. java多线程生产者消费者
  6. JAVA并发编程的艺术目录
  7. PDF 补丁丁 0.4.1 版将增加嵌入中文字库的功能
  8. Swing多线程
  9. Android--将字节数转化为B,KB,MB,GB的方法
  10. 提升c++builder 代码输入流畅度的配置
  11. [jobdu]矩形覆盖
  12. SQL数据库知识二(Day 25)
  13. Legendary Items-微软实习生笔试第一题
  14. JQuery常用知识点及示例
  15. 编译VisualVM源码解决乱码问题
  16. redis 系列7 数据结构之跳跃表
  17. Sleep和wait
  18. 开源医学图像处理平台NiftyNet介绍
  19. C#Winform的DEV下拉下拉控件介绍
  20. S5PV210中断体系结构分析

热门文章

  1. 批量ping IP并检测IP延迟率和丢包率脚本
  2. paper:synthesizable finit state machine design techniques using the new systemverilog 3.0 enhancements之全0/1/z/x的SV写法
  3. 通过composer安装阿里大于接口扩展
  4. POJ:3228-Gold Transportation(要求最小生成树最大边最小)
  5. 线段树:CDOJ1597-An easy problem C(区间更新的线段树)
  6. python面试题解析(数据库和缓存)
  7. Java常用api和操作必背
  8. oracle游标遍历
  9. 一步一步解剖Libevent源代码 - 0
  10. 微信小程序的那些坑