Sum of MSLCM

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<sstream>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %I64d\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
int main()
{
// freopen("E.in","r",stdin);
// freopen(".out","w",stdout);
ll n;
while(cin>>n&&n) {
ll ans=0;
for(ll i=1;i<=n;) {
ll t=n/(n/i);
ll p=(i+t)*(t-i+1)/2;
ans+=n/i*p;
i=t+1;
}
ans--;
cout<<ans<<endl;
}


return 0;
}

Numbered Cards

You have N cards and each has an unique number between 1 and N written on it. In how many
ways can you select a non-empty subset of the cards such that the number written on any two of your
selected cards don’t have any common digits?
For example, when N = 12, {1, 2, 3}, {2, 11}, {3, 4, 5, 6, 7, 8, 9, 12} are some valid selections. But
{1, 2, 10}, {2, 5, 12} are not allowed.

数位dp

The Hypnotic Spirals

阿基米德螺旋线到θ角为止所围面积=a2θ32
我特判了:
1条直线的情况
有一条ray为x=0的情况
注意一开始的一圈
注意跨越x=0轴部分的面积要特判
注意n=0特判

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<sstream>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %I64d\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
#define MAXN (20+10)
#define MAXM (1000+10)
ld PI = 3.141592653589793238462643383;
double a,xita[MAXN];
int n,m;
pair<double,double> q[MAXM];
double calcS(double xit) {
return xit*xit*xit;
}
double calc() {
ld k=2*PI*a;
vector<pi > v;
bool b=0;
Rep(i,m) {
double xit=q[i].se,r=q[i].fi;
if (0<xit && xit < xita[0] && r<a*xit ) {
b=1; continue;
}
int bl;
if (xit<xita[0] || xit>xita[n-1]) bl=n-1;
else bl=lower_bound(xita,xita+n,q[i].se)-xita-1;
int p;
if (r<a*xit) p=0;
else p=(int)(0.5+ceil((r-a*xit)/k));
if (bl==n-1) {
if (0<=xit && xit<xita[0] ) p--;
}
v.pb(mp(bl,p));
// cout<<bl<<' '<<p<<endl;
}
sort(v.begin(),v.end());
int sz=unique(v.begin(),v.end())-v.begin();
double ans=0;
if (b) ans+=xita[0]*xita[0]*xita[0];

Rep(i,sz) {
int lx = v[i].fi,rx=(v[i].fi+1)%n;
double l = xita[lx], r = xita[rx];
if (lx==n-1) r+=2*PI;
double p=v[i].se;
{
double l1 = l + (p-1)*2*PI , r1 = r+ (p-1)*2*PI;
double l2 = l1 + 2*PI , r2 = r1 + 2*PI;
l1=max(l1,0.); l2=max(l2,0.);
r1=max(r1,0.); r2=max(r2,0.);

ans+=r2*r2*r2-l2*l2*l2;
ans-=r1*r1*r1-l1*l1*l1;
}
}
ans=ans*a*a/6;
return ans;
}
double calc2() {
vector< int > v;
double k=2*PI*a;
Rep(i,m) {
double xit=q[i].se,r=q[i].fi;
if (r<a*xit &&0<xit && xit<xita[0]) v.pb(0);
else {
int p;
{
p=(0.5+ceil((r-a*xit)/k));
if (0<=xit && xit<xita[0] ) p--;
v.pb(p+1);
}
}
}
sort(v.begin(),v.end());
int sz=unique(v.begin(),v.end())-v.begin();
double ans=0;
Rep(i,sz) {
int c=v[i];
if (v[i]==0) {
ans+=calcS(xita[0]);
} else {
double r=xita[0]+2*PI*c,l1=r-2*PI,l2=l1-2*PI;
r=max(r,0.); l1=max(l1,0.); l2=max(l2,0.);
ans+=r*r*r-l1*l1*l1;
ans-=l1*l1*l1-l2*l2*l2;
}
}
return ans*a*a/6;

}
int main()
{
// freopen("J.in","r",stdin);
// freopen(".out","w",stdout);
int T=read();
For(kcase,T) {
scanf("%lf",&a);
n=read();
Rep(i,n) scanf("%lf",&xita[i]);
sort(xita,xita+n);
m=read();
Rep(i,m) {
scanf("%lf%lf",&q[i].fi,&q[i].se);
}
printf("Spiral %d:",kcase);
if (n==0) {
printf(" -1\n");
} else if (n==1) {
printf(" %.4lf liters\n",calc2()/10);
} else {
printf(" %.4lf liters\n",calc()/10);
}
}


return 0;
}