Code(hdu5212)
Code
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 877 Accepted Submission(s): 348
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;
}
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 #include <iostream>
2 #include<stdio.h>
3 #include<algorithm>
4 #include<string.h>
5 #include<queue>
6 #include<set>
7 #include<math.h>
8 #include<vector>
9 typedef long long LL;
10 using namespace std;
11 bool prime[10005];
12 int ak[10005];
13 LL mul[10005];
14 LL cnt[10005];
15 vector<int>vec[10005];
16 int mod = 10007;
17 int main(void)
18 {
19 int i,j;
20 int cn = 0;
21 mul[1] = 1;
22 for(i = 2; i <= 10000; i++)
23 {
24 if(!prime[i])
25 {
26 ak[cn++] = i;
27 mul[i] = -1;
28 }
29 for(j = 0; j < cn&&(LL)ak[j]*i<=10000; j++)
30 {
31 if(i%ak[j])
32 {
33 prime[i*ak[j]] = true;
34 mul[i*ak[j]] = -mul[i];
35 }
36 else
37 {
38 prime[i*ak[j]] = true;
39 mul[i*ak[j]] = 0;
40 break;
41 }
42 }
43 }
44 int n;
45 for(i = 1;i <= 10000;i++)
46 {
47 for(j = 1;j <= sqrt(i);j++)
48 {
49 if(i%j==0)
50 {
51 vec[i].push_back(j);
52 if(i/j!=j)
53 vec[i].push_back(i/j);
54 }
55 }
56 }
57 while(scanf("%d",&n)!=EOF)
58 { int maxx = 0;
59 memset(cnt,0,sizeof(cnt));
60 int i,j;
61 for(i = 0; i < n; i++)
62 {scanf("%d",&ak[i]);maxx = max(maxx,ak[i]);}
63 for(i = 0; i < n; i++)
64 {
65 for(j = 0;j < vec[ak[i]].size();j++)
66 { int x = vec[ak[i]][j];
67 cnt[x]++;
68 }
69 }//printf("%lld\n",cnt[1]);
70 LL sum = 0;
71 for(i = 1;i <= maxx;i++)
72 {
73 for(j = i;j <= maxx;j+=i)
74 {
75 sum = sum + mul[j/i]*(cnt[j]*cnt[j])*(i*(i-1)%mod)%mod;
76 sum%=mod;
77 }
78 }
79 printf("%lld\n",(sum%mod+mod)%mod);
80 }
81 return 0;
82 }
Code(hdu5212)的更多相关文章
- Visual Studio Code 代理设置
Visual Studio Code (简称 VS Code)是由微软研发的一款免费.开源的跨平台文本(代码)编辑器,在十多年的编程经历中,我使用过非常多的的代码编辑器(包括 IDE),例如 Fron ...
- 我们是怎么做Code Review的
前几天看了<Code Review 程序员的寄望与哀伤>,想到我们团队开展Code Review也有2年了,结果还算比较满意,有些经验应该可以和大家一起分享.探讨.我们为什么要推行Code ...
- Code Review 程序员的寄望与哀伤
一个程序员,他写完了代码,在测试环境通过了测试,然后他把它发布到了线上生产环境,但很快就发现在生产环境上出了问题,有潜在的 bug. 事后分析,是生产环境的一些微妙差异,使得这种 bug 场景在线下测 ...
- 从Script到Code Blocks、Code Behind到MVC、MVP、MVVM
刚过去的周五(3-14)例行地主持了技术会议,主题正好是<UI层的设计模式——从Script.Code Behind到MVC.MVP.MVVM>,是前一天晚上才定的,中午花了半小时准备了下 ...
- 在Visual Studio Code中配置GO开发环境
一.GO语言安装 详情查看:GO语言下载.安装.配置 二.GoLang插件介绍 对于Visual Studio Code开发工具,有一款优秀的GoLang插件,它的主页为:https://github ...
- 代码的坏味道(14)——重复代码(Duplicate Code)
坏味道--重复代码(Duplicate Code) 重复代码堪称为代码坏味道之首.消除重复代码总是有利无害的. 特征 两个代码片段看上去几乎一样. 问题原因 重复代码通常发生在多个程序员同时在同一程序 ...
- http status code
属于转载 http status code:200:成功,服务器已成功处理了请求,通常这表示服务器提供了请求的网页 404:未找到,服务器未找到 201-206都表示服务器成功处理了请求的状态代码,说 ...
- Visual Studio Code——Angular2 Hello World 之 2.0
最近看到一篇用Visual Studio Code开发Angular2的文章,也是一篇入门教程,地址为:使用Visual Studio Code開發Angular 2專案.这里按部就班的做了一遍,感觉 ...
- WebStorm 2016 最新版激活(activation code方式)
WebStorm 2016 最新版激活(activation code方式) WebStorm activation code WebStorm 最新版本激活方式: 今天下载最新版本的WebStorm ...
随机推荐
- react native安装遇到的问题
最近学习react native 是在为全栈工程师而努力,看网上把react native说的各种好,忍不住学习了一把.总体感觉还可以,特别是可以开发android和ios这点非常厉害,刚开始入门需要 ...
- 带你全面了解 OAuth2.0
最开始接触 OAuth2.0 的时候,经常将它和 SSO单点登录搞混.后来因为工作需要,在项目中实现了一套SSO,通过对SSO的逐渐了解,也把它和OAuth2.0区分开了.所以当时自己也整理了一篇文章 ...
- A Child's History of England.26
CHAPTER 9 ENGLAND UNDER WILLIAM THE SECOND, CALLED RUFUS William the Red, in breathless haste, secur ...
- css相关,flex布局全通!
寻根溯源话布局 一切都始于这样一个问题:怎样通过 CSS 简单而优雅的实现水平.垂直同时居中. 记得刚开始学习 CSS 的时候,看到 float 属性不由得感觉眼前一亮,顺理成章的联想到 Word 文 ...
- 简化版chmod
我们知道对文件访问权限的修改在Shell下可通过chmod来进行 例如 可以看到v.c文件从无权限到所有者可读可写可执行.群组和其他用户可读可执行 chmod函数原型 int chmod(const ...
- centOS7.4 , gcc4.8.5装cgdb
从github上clone最新releast后进入文件夹 ./configure –prefix=/usr/local CXXFLAGS=-std=c++11 make&make instal ...
- this指针的用法和基本分析
当在不同的对象中采用this指针,就已经是在给它赋值了.对象各自的this指针指向各自对象的首地址,所以不同对象的this指针一定指向不同的内存地址. this 指针是由系统自动提供的指向对象的特殊指 ...
- 理解css中的 content:" " 是什么意思
css中的属性是插入生成的内容,它一般与伪元素:befor和 :after 配合使用. content:"." 就表示在需要的地方插入"." 注意:如果已经规定 ...
- 【C/C++】旋转数组的最小数字/ 剑指offer
#include <bits/stdc++.h> using namespace std; class Solution { public: int minNumberInRotateAr ...
- 【C#】【MySQL】C#连接MySQL数据库(三)登陆注册代码
项目结构 项目代码 WebForm_Login.aspx <%@ Page Language="C#" AutoEventWireup="true" Co ...