hdu 5212 Code 筛法或者莫比乌斯
Code
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
The function:
int calc
{
int res=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
res+=gcd(a[i],a[j])*(gcd(a[i],a[j])-1);
res%=10007;
}
return res;
}
For each case:
The first line contains an integer N(1≤N≤10000).
The next line contains N integers a1,a2,...,aN(1≤ai≤10000).
Print an integer,denoting what the function returns.
1 3 4 2 4
gcd(x,y) means the greatest common divisor of x and y.
先占坑,晚点补莫比乌斯
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define eps 1e-8
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e4+,M=1e6+,inf=1e9+;
const LL INF=1e18+,mod=1e9+; int cnt[N],sum[N];
int main()
{
int n;
while(~scanf("%d",&n))
{
memset(cnt,,sizeof(cnt));
memset(sum,,sizeof(sum));
for(int i=;i<=n;i++)
{
int x;
scanf("%d",&x);
cnt[x]++;
}
for(int i=;i<=;i++)
{
for(int j=i;j<=;j+=i)
sum[i]+=cnt[j];
sum[i]=sum[i]*sum[i];
}
LL ans=;
for(int i=;i>=;i--)
{
for(int j=i+i;j<=;j+=i)
sum[i]-=sum[j];
//if(sum[i])cout<<i<<" "<<sum[i]<<endl;
ans+=1LL*i*(i-)*sum[i];
ans%=;
}
printf("%lld\n",ans);
}
return ;
}
hdu 5212 Code 筛法或者莫比乌斯的更多相关文章
- HDU 5212 Code【莫比乌斯反演】
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5212 题意: 给定序列,1≤i,j≤n,求gcd(a[i],a[j])∗(gcd(a[i],a[j] ...
- hdu.5212.Code(莫比乌斯反演 && 埃氏筛)
Code Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submi ...
- HDU 5212 Code (莫比乌斯反演)
题意:给定上一个数组,求 析: 其中,f(d)表示的是gcd==d的个数,然后用莫比乌斯反演即可求得,len[i]表示能整队 i 的个数,可以线性筛选得到, 代码如下: #pragma comment ...
- hdu 5212 : Code【莫比乌斯】
题目链接 题给代码可以转化为下面的公式 然后用F[n]记录公约数为n的(a[i],a[j])对数,用f[n]记录最大公约数为n的(a[i],a[j])对数 之后枚举最大公约数d 至于求F[n],可以先 ...
- HDU 5212 Code
筛法. 统计所有 [数] 的所有 [倍数] 的 [数] 的个数,即 i 的所有倍数 i, 2i, 3i, 4i...个数为 dp[i], 则所有 倍数两两结合共有 dp[i] * dp[i] 个. 此 ...
- HDU 5212 莫比乌斯反演
Code Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- HDU 2841 Visible Trees(莫比乌斯反演)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2841 题意:给n*m的矩阵(从(1,1)开始编号)格子,每个格子有一棵树,人站在(0,0)的位置,求可 ...
- HDU 3461 Code Lock(并查集+二分求幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3461 A lock you use has a code system to be opened in ...
- HDU 5167 Fibonacci 筛法+乱搞
题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5167 题意: 给你一个x,判断x能不能由斐波那契数列中的数相乘得到(一个数可以重复使用) ...
随机推荐
- vue各种实例集合
注意:以下所有示例基于vue 2.x.Vuex 2.x. vm.$mount()-挂载: <body> <div id="a"> </div> ...
- Shell 比较两个数的大小
格式很重要多一个空格少一个空格都可能出错 li@ubuntu:~/test$ cat compare.sh #!/bin/bash read x read y if [ $x -lt $y ] the ...
- sparkStreaming插入mysql 必须考虑到实时更新老的key
原先使用批次提交更新 但数据库无变化,不得不一条一条的插入 公司数据量不大 还未做数据量大的测试 但实时更新是可以的 关键sql : insert into area_user_amt (date, ...
- 自写Jquery插件 Datagrid
原创文章,转载请注明出处,谢谢!https://www.cnblogs.com/GaoAnLee/p/9086582.html 废话不多说,先上个整体效果: html <div id='data ...
- 利用yum搭建lamp环境并进一步创建博客
用yum搭建lamp环境 第一.安装apache yum -y install httpd 第二.安装mariadb Yum -y mariadb mariadb-server 第三.安装php Yu ...
- 原生tab选项卡制作
html部分 <div class="tab"> <div class="nav"> <ul> <li class=& ...
- STM32硬件IIC (转)
源: STM32硬件IIC
- PyTorch 中,nn 与 nn.functional 有什么区别?
作者:infiniteft链接:https://www.zhihu.com/question/66782101/answer/579393790来源:知乎著作权归作者所有.商业转载请联系作者获得授权, ...
- What is probabilistic programming? | 中文翻译
What is probabilistic programming? | 中文翻译 Probabilistic languages can free developers from the compl ...
- html5-Input类型
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>html5-Input类型& ...