首页 技术 正文
技术 2022年11月17日
0 收藏 392 点赞 4,663 浏览 1752 个字

CA Loves GCD

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 882    Accepted Submission(s):
305

Problem DescriptionCA is a fine comrade who loves the party and people;
inevitably she loves GCD (greatest common divisor) too.
Now, there are Nhdu 5656 CA Loves GCD

different numbers. Each time, CA will select several numbers (at least one),
and find the GCD of these numbers. In order to have fun, CA will try every
selection. After that, she wants to know the sum of all GCDs.
If and only if
there is a number exists in a selection, but does not exist in another one, we
think these two selections are different from each other.  InputFirst line contains Thdu 5656 CA Loves GCD

denoting the number of testcases.
Thdu 5656 CA Loves GCD

testcases follow. Each testcase contains a integer in the first time, denoting
Nhdu 5656 CA Loves GCD

, the number of the numbers CA have. The second line is Nhdu 5656 CA Loves GCD

numbers.
We guarantee that all numbers in the test are in the range
[1,1000].
1≤T≤50hdu 5656 CA Loves GCD

 OutputThdu 5656 CA Loves GCD

lines, each line prints the sum of GCDs mod 100000007hdu 5656 CA Loves GCD

.

 Sample Input222 431 2 3 Sample Output810 SourceBestCoder
Round #78 (div.2)
 Recommendwange2014   |   We have carefully selected several
similar problems for you:  5659 5658 5657 5654 5653  第一次用了三个for循环,结果直接超时,在大神的教导下,改用标记求值,十分巧妙(结果非常大,不要忘记取余!!!)。 题意:输入T,代表T个测试数据,再输入n表示n个数,接着输入n个数,求每次至少取一个数,最后的最大公约数之和为多少。(比如第一组数据,2 4   第一次取2,公约数为2,第二次取4,公约数为4,第三次取2,4,公约数为2,所有公约数和为8) 附上代码: 

 #include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#define mod 100000007
using namespace std; int xx(int a,int b)
{
int c,t;
if(a<b)
{
t=a;
a=b;
b=t;
}
while(b)
{
c=a%b;
a=b;
b=c;
}
return a;
} int main()
{
int T,i,j,a,b,k,n,m,w;
int ai[];
long long vis[];
scanf("%d",&T);
while(T--)
{
long long sum=;
scanf("%d",&n);
memset(vis,,sizeof(vis));
for(i=; i<n; i++)
{
scanf("%d",&ai[i]);
}
for(i=; i<n; i++)
{
for(j=; j<=; j++)
if(vis[j])
{
vis[xx(ai[i],j)]=(vis[xx(ai[i],j)]+vis[j])%mod;
}
vis[ai[i]]=(vis[ai[i]]+)%mod;
}
for(i=; i<=; i++)
if(vis[i])
sum=(sum+(i*vis[i])%mod)%mod;
printf("%I64d\n",sum);
}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,489
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,904
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,490
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,291