思路:对于每个数分解质因子然后记录每一个质因子的个数,对与在b中出现的质因子就减去1,否则加1,求出总的,然后从后面一次对它们的最大公约数,然后判断除以最大公约数之后,改变量是不是变化,求最大值,变化量为负值的话减去。

 #include <cstdio>
#include <cstring>
#include <map>
#include <set>
#include <algorithm>
using namespace std; set<int>q;
int n,m;
int a[],b[];
int g[]; int gcd(int a,int b)
{
return b==?a:gcd(b,a%b);
} int Get_num(int x)
{
int ans=;
map<int,int>p;
for(int j=; j*j<=x; j++)
{
if(x%j==)
{
while(x%j==)
{
p[j]++;
x/=j;
}
}
}
if(x>) p[x]++;
map<int,int>::iterator it;
for(it=p.begin(); it!=p.end(); it++)
{
if(q.find(it->first)==q.end()) ans+=it->second;
else ans-=it->second;
}
return ans;
} int main()
{ scanf("%d%d",&n,&m);
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
}
for(int j=; j<=m; j++)
{
scanf("%d",&b[j]);
q.insert(b[j]);
}
int ans=;
for(int i=; i<=n; i++)
{
ans+=Get_num(a[i]);
}
for(int i=; i<=n; i++)
{
if(i==) g[i]=a[i];
else g[i]=__gcd(g[i-],a[i]);
}
int c=;
for(int i=n; i>=; i--)
{
int h=g[i]/c;
int s=Get_num(h);
if(s<)
{
ans-=s*i;
c*=h;
}
}
printf("%d\n",ans);
return ;
}

codeforces Upgrading Array的更多相关文章

  1. Codeforces 494D Upgrading Array

    http://codeforces.com/contest/494/problem/D 题意:给一个数组,和一个坏质数集合,可以无数次地让1到i这些所有数字除以他们的gcd,然后要求Σf(a[i])的 ...

  2. Codeforces 402D Upgrading Array:贪心 + 数学

    题目链接:http://codeforces.com/problemset/problem/402/D 题意: 给你一个长度为n的数列a[i],又给出了m个“坏质数”b[i]. 定义函数f(s),其中 ...

  3. codeforces 402 D. Upgrading Array(数论+贪心)

    题目链接:http://codeforces.com/contest/402/problem/D 题意:给出一个a串和素数串b .f(1) = 0; p为s的最小素因子如果p不属于b , 否则 . a ...

  4. CodeForces 402D Upgrading Array (数学+DP)

    题意:给出一个数列,可以进行一种操作将某一个前缀除去他们的gcd,有一个函数f(x),f(1) = 0 , f(x) = f(x/p)+1,f(x) = f(x/p)-1(p是坏素数), 求 sum( ...

  5. Codeforces 797E - Array Queries

    E. Array Queries 题目链接:http://codeforces.com/problemset/problem/797/E time limit per test 2 seconds m ...

  6. Codeforces 1108E2 Array and Segments (Hard version) 差分, 暴力

    Codeforces 1108E2 E2. Array and Segments (Hard version) Description: The only difference between eas ...

  7. CodeForces 300A Array

    http://codeforces.com/problemset/problem/300/A 题意 :给你n个数字,让你分成3组,第一组各个数之积要小于0,第二组要大于0,第三组要等于0,符合要求的答 ...

  8. CF_402D Upgrading Array 因式分解

    题目链接:http://codeforces.com/problemset/problem/402/D /**算法分析: */ #include<bits/stdc++.h> #defin ...

  9. 网络流(最大流):CodeForces 499E Array and Operations

    You have written on a piece of paper an array of n positive integers a[1], a[2], ..., a[n] and m goo ...

随机推荐

  1. Delphi下实现全屏快速找图找色

    前言 最近有好几个朋友都在问我找图找色的问题,奇怪?于是乎写了一个专门用于找图找色的单元文件“BitmapData.pas”.在这个单元文件中我实现了从文件中导入位图.屏幕截图.鼠标指针截图.在图片上 ...

  2. 通过WriteProcessMemory改写进程的内存

    http://www.cnblogs.com/feiyucq/archive/2009/10/21/1587628.html 以PROCESS_ALL_ACCESS权限打开进程以后既能够使用ReadP ...

  3. [Angular + Unit] AngularJS Unit testing using Karma

    http://social.technet.microsoft.com/wiki/contents/articles/32300.angularjs-unit-testing-using-karma- ...

  4. LINUX 内核调试基础+编程基础

    http://blog.chinaunix.net/uid-20564848-id-73208.html 内核文档:[root@localhost Documentation]# pwd /usr/s ...

  5. [转] nginx 开启gzip压缩--字符串压缩比率很牛叉

    http://www.cnblogs.com/dasn/articles/3716055.html 刚刚给博客加了一个500px相册插件,lightbox引入了很多js文件和css文件,页面一下子看起 ...

  6. JavaScript - 运算符 == 与 === 的区别

    在 JavaScript 中,运算符 == 与 === 都是用来比较两个值是否相等.但是这两个操作符有个不同的地方:== 并不表示严格相等,而 === 表示进行严格比较,不仅比较值,而且会比较变量的类 ...

  7. 学习java随笔第二篇:java开发工具——Eclipse

    java开发工具有很多这里我使用的是Eclipse. 首先我在官网上下载了Eclipse的软件包,下载地址:http://www.eclipse.org/downloads/,然后有在网上找了一个汉化 ...

  8. 实现Android K的伪沉浸式

    在Android 5.0之后引入了MD风格,从而状态栏沉浸也成为了一种设计习惯.而停留在之Android L之前的Android系统则不能直接实现沉浸式,这里就介绍一下如何实现Android K系列的 ...

  9. openwrt advanced configuration

    openwrt高级配置(汗 照着标题就翻译过来了) openwrt Kamikaze 8.09的一般配置文件都在目录 /etc/config 下面,可以使用脚本来调用参数和设置参数. 比如 sbin/ ...

  10. windows下eclipse+hadoop2

    windows下eclipse+hadoop2.4开发手册 1.解压下载的hadoop2.4,到任意盘符,例如D:\hadoop-2.4.0. 2.设置环境变量 ①新建系统变量,如下所示. ②将新建的 ...