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 ...
随机推荐
- 7本Python必读的入门书籍,你看过吗?(附福利)
Python入门书籍不用看太多,看一本就够.重要的是你要学习Python的哪个方向,或者说你对什么方向感兴趣,因为Python这门语言的应用领域比较广泛,比如说可以用来做数据分析.机器学习,也可以用来 ...
- 日常Java测试第一段 2021/11/12
课堂测试一 package word_show;import java.io.BufferedReader;import java.io.FileNotFoundException;import ja ...
- 疯了吧!这帮人居然用 Go 写“前端”?(一)
作者 | 郑嘉涛(羣青) 来源 | 尔达 Erda 公众号 无一例外,谈到前后端分离"必定"是 RESTful API,算是定式了.但我们知道 REST 在资源划分上的设计总是 ...
- Mybatis逆向工程简单介绍
转自:https://blog.csdn.net/yerenyuan_pku/article/details/71909325 什么是逆向工程 MyBatis的一个主要的特点就是需要程序员自己编写sq ...
- 通信方案软件设计(环形动态申请内存,支持USART+IIC+SPI+CAN协议
1 <STM32进阶之串口环形缓冲区实现>中讲得比较清楚(链接) 2 amobbs中讲的方法有点复杂,以下是链接和参考源码: 通信方案软件设计(环形动态申请内存,支持USART+IIC+S ...
- 【STM32】WS2812介绍、使用SPI+DMA发送数据
这篇要使用到SPI+DMA,需要了解的话,可以参考我另两篇博客 时钟:https://www.cnblogs.com/PureHeart/p/11330967.html SPI+DMA通信:https ...
- Shell变量与算术运算
区分两个 Shell Shell 语言与 Shell 解释器 Shell 语言 写 Shell 脚本使用的是 Shell 语言,Shell 既是一种命令语言,又是一种程序设计语言. 作为命令语言,它交 ...
- 转Android service 启动篇之 startForegroundService
本文转自:https://blog.csdn.net/shift_wwx/article/details/82496447 前言: 在官方文档 Android 8.0 行为变更 中有这样一段话: An ...
- 【Git】【Gitee】通过git远程删除仓库文件
安装Git Git安装配置-菜鸟教程 没有安装下载的,请读者自行安装下载. 启动与初步配置 配置用户名与邮箱 git config --global user.name "用户名" ...
- Java如何生成随机数 - Random、ThreadLocalRandom、SecureRandom
Java7 的Random伪随机数和线程安全的ThreadLocalRandom 一.Random伪随机数: Random 类专门用于生成一个伪随机数,它有两个构造器: 一个构造器使用默认的种子(以当 ...