CodeTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1452 Accepted Submission(s): 605 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?
Input There are Multiple Cases.(At MOST 10 )
Output For each case:
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
Recommend hujie |
类似于这道题https://blog.csdn.net/lanshan1111/article/details/99335072
#include <algorithm> //STL通用算法
#include <bitset> //STL位集容器
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex> //复数类
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque> //STL双端队列容器
#include <exception> //异常处理类
#include <fstream>
#include <functional> //STL定义运算函数(代替运算符)
#include <limits>
#include <list> //STL线性列表容器
#include <map> //STL 映射容器
#include <iomanip>
#include <ios> //基本输入/输出支持
#include<iosfwd> //输入/输出系统使用的前置声明
#include <iostream>
#include <istream> //基本输入流
#include <ostream> //基本输出流
#include <queue> //STL队列容器
#include <set> //STL 集合容器
#include <sstream> //基于字符串的流
#include <stack> //STL堆栈容器
#include <stdexcept> //标准异常类
#include <streambuf> //底层输入/输出支持
#include <string> //字符串类
#include <utility> //STL通用模板类
#include <vector> //STL动态数组容器
#include <cwchar>
#include <cwctype>
#define ll long long
using namespace std;
priority_queue<int,vector<int>,less<int> >q;
int dx[]= {-1,1,0,0,-1,-1,1,1};
int dy[]= {0,0,-1,1,-1,1,1,-1};
const int maxn = 100000+66;
const ll mod=10007;
int n,k,m;
int a[maxn];
int cnt[maxn];
int f[maxn];
int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(cnt,0,sizeof(cnt));
memset(f,0,sizeof(f));
for(int i=1; i<=n; i++)
{
scanf("%d",&a[i]);
for(int j=1; j*j<=a[i]; j++)
{
if(a[i]%j==0)
{
cnt[j]++;
if(j*j!=a[i])
{
cnt[a[i]/j]++;
}
}
}
}
int ans=0;
for(int i=10000; i>=1; i--)
{
f[i]=cnt[i]*cnt[i]%mod;
for(int j=i*2; j<=10000; j+=i)
{
f[i]=(f[i]-f[j])%mod;
f[i]=(f[i]%mod+mod)%mod;
}
int v=i*(i-1)%mod;
ans=(ans+v*f[i]%mod)%mod;
}
printf("%d\n",ans%mod);
}
return 0;
}