HDU 5212 Code
来源:互联网 发布:ezdmc编程 编辑:程序博客网 时间:2024/05/29 08:16
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;
}
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 integerN(1≤N≤10000) .
The next line containsN integers a1,a2,...,aN(1≤ai≤10000) .
For each case:
The first line contains an integer
The next line contains
Output
For each case:
Print an integer,denoting what the function returns.
Print an integer,denoting what the function returns.
Sample Input
51 3 4 2 4
Sample Output
64Hintgcd(x,y) means the greatest common divisor of x and y.
自己yy的做法,明明是可以过的,比赛的时候用了longlong转换int结果一直wa,也是醉了。
#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>#include<stack>using namespace std;const int maxn = 10005;const int base = 10007;int T, n, k, a[maxn], f[maxn], x, y, tot, F[maxn], ans;bool cmp(const int &a, const int &b){return a > b;}struct abc{int x, y;abc(int x, int y) :x(x), y(y){};abc(){};bool operator<(const abc&a){return x > a.x;}}b[maxn];int main(){while (scanf("%d", &n) != EOF){memset(f, 0, sizeof(f));memset(F, 0, sizeof(F));ans = 0;for (int i = 1; i <= n; i++){scanf("%d", &a[i]);ans = (ans + a[i] * (a[i] - 1)) % base;}sort(a + 1, a + n + 1, cmp);for (int i = 1; i <= n; i++){tot = 0;int k = sqrt(1.0*a[i]);for (int j = 1; j <= k; j++){if (a[i] % j == 0){b[tot++] = abc(j, f[j]++);if (a[i] != j*j) b[tot++] = abc(a[i] / j, f[a[i] / j]++);}}sort(b, b + tot);for (int j = 0; j < tot; j++)for (int k = j + 1; k < tot; k++)if (b[j].x%b[k].x == 0) b[k].y -= b[j].y;for (int j = 0; j < tot; j++) F[b[j].x] += b[j].y;}for (int i = 2; i < maxn; i++){x = 2 * F[i] % base;x = x*i % base;x = x*(i - 1) % base;ans = (ans + x) % base;ans = (ans + base) % base;}printf("%d\n", ans);}return 0;}
0 0
- HDU 5212 Code
- hdu 5212 code
- hdu 5212 Code
- HDU 5212 Code
- hdu 5212 Code
- hdu 5212 Code
- hdu 5212 Code (容斥)
- hdu 5212 Code (数论)
- Code HDU
- Code HDU 5212(容斥原理)
- HDU 5212 Code(容斥)
- hdu 5212 Code【容斥原理】【思维】
- Hdu 5212 Code【容斥原理】
- HDU 5212 Code GCD容斥(套路).
- hdu 3461 Code Lock
- hdu B. Code Parsing
- hdu 3461 Code Lock
- HDU-#4813 Hard Code
- 【排序算法的JavaScript实现】
- 在浏览器中打开预览sublime text当前所编辑文件的方法和快捷键设置
- Posts Tagged 【math】Count Primes
- Media Player控件使用
- 科目三考试挂掉原因分析
- HDU 5212 Code
- Linux下用mail命令发送邮件
- centos6.5 安装pomelo和nodejs环境
- vss的ss.ini丢失或损坏导致的vss无法登录错误
- hadoop配置、运行错误总结[二]
- 如何在SharePoint 2013 创建Power pivot 库(How to create a PowerPivot Gallery )及错误解决方法
- 在linux环境下构建ipsec vpn的过程
- 车牌号识别
- Linked List Cycle II