2809: OH哥的倍数问题(Hard Version)
#include<stdio.h>
typedef long long LL;
int n;
LL get(int x){
return 1LL*(1+n/x)*(n/x)*x/2;}
int gcd(int a,int b){
return b?gcd(b,a%b):a;}
int lcm(int a,int b,int c,int d,int e)
{
int x=a*b/gcd(a,b);x=x*c/gcd(x,c);x=x*d/gcd(x,d);x=x*e/gcd(x,e);return x;
}
int main()
{
int T;scanf("%d",&T);while(T--){
int a,b,c,d,e;scanf("%d%d%d%d%d%d",&n,&a,&b,&c,&d,&e);LL res=get(a)+get(b)+get(c)+get(d)+get(e)-get(lcm(a,b,1,1,1))-get(lcm(a,c,1,1,1))-get(lcm(a,d,1,1,1))-get(lcm(a,e,1,1,1))-get(lcm(b,c,1,1,1))-get(lcm(b,d,1,1,1))-get(lcm(b,e,1,1,1))-get(lcm(c,d,1,1,1))-get(lcm(c,e,1,1,1))-get(lcm(d,e,1,1,1))+get(lcm(a,b,c,1,1))+get(lcm(a,b,d,1,1))+get(lcm(a,b,e,1,1))+get(lcm(a,c,d,1,1))+get(lcm(a,c,e,1,1))+get(lcm(a,d,e,1,1))+get(lcm(b,c,d,1,1))+get(lcm(b,c,e,1,1))+get(lcm(b,d,e,1,1))+get(lcm(c,d,e,1,1))-get(lcm(a,b,c,d,1))-get(lcm(a,b,c,e,1))-get(lcm(a,b,d,e,1))-get(lcm(a,c,d,e,1))-get(lcm(b,c,d,e,1))+get(lcm(a,b,c,d,e));printf("%lld\n",res);}return 0;
}