Code

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Problem Description
WLD likes playing with codes.One day he is writing a function.Howerver,his computer breaks down because the function is too powerful.He is very sad.Can you help him?

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;

}

 
Input
There are Multiple Cases.(At MOST 10)

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).

 
Output
For each case:

Print an integer,denoting what the function returns.

 
Sample Input
5
1 3 4 2 4
 
Sample Output
64

Hint

gcd(x,y) means the greatest common divisor of x and y.

 
Source

先占坑,晚点补莫比乌斯

#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 筛法或者莫比乌斯的更多相关文章

  1. 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] ...

  2. hdu.5212.Code(莫比乌斯反演 && 埃氏筛)

    Code Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submi ...

  3. HDU 5212 Code (莫比乌斯反演)

    题意:给定上一个数组,求 析: 其中,f(d)表示的是gcd==d的个数,然后用莫比乌斯反演即可求得,len[i]表示能整队 i 的个数,可以线性筛选得到, 代码如下: #pragma comment ...

  4. hdu 5212 : Code【莫比乌斯】

    题目链接 题给代码可以转化为下面的公式 然后用F[n]记录公约数为n的(a[i],a[j])对数,用f[n]记录最大公约数为n的(a[i],a[j])对数 之后枚举最大公约数d 至于求F[n],可以先 ...

  5. HDU 5212 Code

    筛法. 统计所有 [数] 的所有 [倍数] 的 [数] 的个数,即 i 的所有倍数 i, 2i, 3i, 4i...个数为 dp[i], 则所有 倍数两两结合共有 dp[i] * dp[i] 个. 此 ...

  6. HDU 5212 莫比乌斯反演

    Code Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  7. HDU 2841 Visible Trees(莫比乌斯反演)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2841 题意:给n*m的矩阵(从(1,1)开始编号)格子,每个格子有一棵树,人站在(0,0)的位置,求可 ...

  8. 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 ...

  9. HDU 5167 Fibonacci 筛法+乱搞

    题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5167 题意: 给你一个x,判断x能不能由斐波那契数列中的数相乘得到(一个数可以重复使用) ...

随机推荐

  1. Codeforce 294A - Shaass and Oskols (模拟)

    Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to ...

  2. Kotlin基础学习

        Kotlin 和 java 都是一种静态类型的编程语言.表达式的类型在编译期已经确定,编译期能验证对象是否包含想访问方法或是字段,维护正确性与性能的同时保持源代码的简洁       静态类型的 ...

  3. GoldenGate实时投递数据到大数据平台(2)- Cassandra

    简介 GoldenGate是一款可以实时投递数据到大数据平台的软件,针对apache cassandra,经过简单配置,即可实现从关系型数据将增量数据实时投递到Cassandra,以下介绍配置过程. ...

  4. JS笔记—01

    1.JS的代码一般在头部写2.当页面载入时,会执行位于body部分的JavaScript当被调用时,位于head部分的JavaScript被执行.3.要对外部的JS文件的一个变量操作,代码是写在内部J ...

  5. 一个简单的购物金额结算(JAVA)

    我编写的代码: import java.util.Scanner; public class ZuoYe01 { public static void main(String[] args) { // ...

  6. 【4opencv】求解向量和轮廓的交点

    在“学习OpenCV3"的QQ群众,网友且行且珍惜针对前期博客(https://www.cnblogs.com/jsxyhelu/p/9345590.html)中的内容提出了以下问题: 比如 ...

  7. C++的STL之map自动排序特性

    #include <iostream> #include <map> using namespace std; int main() {方法一: map<int,int& ...

  8. Bootstrap3基础 btn-xs/sm... 按钮的四种大小

      内容 参数   OS   Windows 10 x64   browser   Firefox 65.0.2   framework     Bootstrap 3.3.7   editor    ...

  9. 开源代码中的autogen.sh干了些什么?

    答:重新根据当前所处环境生成新的configure 分析脚本都做了些什么? 1. 指定make工具 MAKE=gmake or MAKE=make 2. 执行autoreconf autoreconf ...

  10. linux内核中的dquot是什么?

    答:这个与磁盘配额管理(disk quota)有关,内核配置选项为CONFIG_QUOTA,使能此选项意味着可以设置每个用户的硬盘使用限制.