# Bzoj2005[Noi2010]能量采集

Description

Input

Output

Sample Input

【样例输入1】

5 4

【样例输入2】

3 4

Sample Output

【样例输出1】

36

【样例输出2】

20

【数据规模和约定】

/*
* @Author: Heristor
* @Date:   2015-06-09 23:00:59
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <vector>

using namespace std;

#define rep(i,l,r) for(i=l;i<=r;i++)
#define ser(i,r,l) for(i=r;i>=l;i--)
#define INF 100005
#define inf 1000000007

typedef long long ll;
priority_queue<int >QwQ;

int n,m,tot=0;
int in[INF],Phi[INF],Prime[INF];
ll Ans=0,tmp=0;
{
int k=0,f=1;
char ch;
while(ch<'0' || ch>'9'){
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9')k=(k<<1)+(k<<3)+ch-'0',ch=getchar();
return k*f;
}
void init()
{
int i,j,k;
if(n>m)swap(n,m);
Phi[1]=1;
rep(i,2,n){
if(!in[i]){
Phi[i]=i-1;
Prime[++tot]=i;
}
for(j=1;j<=tot && i*Prime[j]<=n;j++){
in[i*Prime[j]]=1;
if(!(i%Prime[j])){
Phi[i*Prime[j]]=Phi[i]*Prime[j];
break;
}
else Phi[i*Prime[j]]=Phi[i]*(Prime[j]-1);
}
}
rep(i,1,n){
tmp=n/i;
tmp*=(ll)m/i;
tmp*=(ll)Phi[i];
Ans+=tmp;
}
Ans*=2;
Ans-=(ll)m*n;
printf("%lld\n",Ans);
}
void work()
{
int i,j,k;
}
int main()
{
freopen("Bzoj2005.in","r",stdin);
freopen("Bzoj2005.out","w",stdout);
init();
work();
return 0;
}

/*
* @Author: Heristor
* @Date:   2016-06-16 11:11:18
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <vector>

using namespace std;

#define rep(i,l,r) for(i=l;i<=r;i++)
#define ser(i,r,l) for(i=r;i>=l;i--)
#define INF 100005
#define inf 1000000007

typedef long long ll;
priority_queue<int >QwQ;

int n,m;
ll Ans=0;
ll f[INF];
{
int k=0,f=1;
char ch;
while(ch<'0' || ch>'9'){
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9')k=(k<<1)+(k<<3)+ch-'0',ch=getchar();
return k*f;
}
void init()
{
int i,j,k;
if(n>m)swap(n,m);
ser(i,n,1){
f[i]=(ll)n/i;
f[i]*=(ll)m/i;
for(j=2*i;j<=n;j+=i)f[i]-=f[j];
Ans+=f[i]*(ll)i;
}
Ans*=2;
Ans-=(ll)m*n;
printf("%lld\n", Ans);
}
void work()
{
int i,j,k;
}
int main()
{
freopen("Bzoj2005.in","r",stdin);
freopen("Bzoj2005.out","w",stdout);
init();
work();
return 0;
}

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客