A.Holiday Of Equality
#include<bits/stdc++.h>
using namespace std;
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma
#define
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("A.in","r",stdin);
// freopen(".out","w",stdout);
int n=read();
int c=0,p=0;
For(i,n) {
int t=read();
c+=t;
p=max(p,t);
}
cout<<n*p-c<<endl;
return 0;
}
B.Blown Garland
#include<bits/stdc++.h>
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;
}
map<char,int> h;
int p[4];
int main()
{
// freopen("B.in","r",stdin);
// freopen(".out","w",stdout);
string s;
cin>>s;
int n=s.length();
Rep(i,n) if (s[i]!='!') h[s[i]]=i%4;
else p[i%4]++;
cout<<p[h['R']]<<' ';
cout<<p[h['B']]<<' ';
cout<<p[h['Y']]<<' ';
cout<<p[h['G']]<<endl;
return 0;
}
C.Unfair Poll
#include<bits/stdc++.h>
using namespace std;
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma
#define
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("C.in","r",stdin);
// freopen(".out","w",stdout);
ll n,m,k,x,y;
cin>>n>>m>>k>>x>>y;
if (n<=2) {
ll mic=k/(n*m);
k%=n*m;
ll ans1=mic,ans2=mic;
if (k) ++ans1;
cout<<ans1<<' '<<ans2<<' ';
ll ans3=mic;
ll p=(x-1)*m+y;
if (p<=k) ans3=ans1;else ans3=ans2;
cout<<ans3<<endl;
return 0;
}
ll mic=k/(m*(n-1));
ll mic1=(mic+1)/2,mic2=mic,mic3=mic/2;
k%=(m*(n-1));
ll mic4=mic1,mic5=mic2,mic6=mic3;
ll ans;
if (x==1) ans=mic1;else if (x==n) ans=mic3;else ans=mic2;
ll pos=(x-1)*m+y;
if (mic%2==0) {
if (k<m) ++mic4;
else if(k==m) ++mic4,++mic1;
else ++mic1,++mic5,++mic4;
if (pos<=k) ++ans;
}
else {
x=n-x+1;
ll pos=(x-1)*m+y;
if (pos<=k) ++ans;
if (k<m) ++mic6;
else if(k==m) ++mic6,++mic3;
else ++mic3,++mic5,++mic6;
}
cout<<max(mic6,max(mic4,mic5))<<' ';
cout<<min(mic1,min(mic2,mic3))<<' ';
cout<<ans<<endl;
return 0;
}
D.Ability To Convert
#include<bits/stdc++.h>
using namespace std;
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma
#define
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;
}
char s[1000];
ll gener(int i,int j) {
if (i==j) return s[i]-'0';
if (s[i]=='0') return -1;
ll p=0;
Fork(k,i,j) {
p=p*10;
p+=s[k]-'0';
}
return p;
}
int main()
{
freopen("D.in","r",stdin);
// freopen(".out","w",stdout);
ll k=read();
cin>>s;
int n=strlen(s);
return 0;
ll ans=0,c=0,m=1,p=1;
RepD(i,n-1)
{
if (s[i]=='0') {
int j=i;
}
ll c2=c+m*(s[i]-'0');
if (c2<k) {
c=c2;
m*=10;
} else {
ans+=p*c;
p*=k;
c=s[i]-'0',m=10;
}
}
if (c) ans+=p*c;
cout<<ans<<endl;
return 0;
}
E.Broken Tree
//waitng for updated
F.Geometrical Progression
如果我们枚举首项和某项,很容易判断,但是O(n2)太慢
不妨考虑枚举an/a1=pn−1=d,当n≥3时,d只有不到1e7以内个取值,直接枚举就好,显然合法d的取值为ijn−1(i≠j,gcd(i,j)=1),好了我们计算首项末项上下界就行
n<=2||n特别大的情况要特判
#include<bits/stdc++.h>
using namespace std;
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma
#define
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;
}
ll gcd(ll a,ll b){
if (!b) return a;return gcd(b,a%b);
}
#define
ll a[MAXN];
int main()
{
// freopen("F.in","r",stdin);
// freopen(".out","w",stdout);
ll n,l,r;
cin>>n>>l>>r;
ll len=r-l+1;
if (n==1) cout<<len;
else if (n==2) cout<<len*(len-1);
else if (n-1>log2(1e7)) cout<<'0';
else {
ll ans=0;
long double c=pow(r,1.0/(n-1.0));
c+=1e-5;
for(ll i=1;i<=c;i++) {
ll p=1;
For(j,n-1) p*=i;
a[i]=p;
}
For(i,c) For(j,i-1) if (gcd(i,j)==1) {
// cout<<a[i]<<'/'<<a[j]<<endl;
ll l1=l/a[j];
if (l%a[j]) ++l1;
ll r1=r/a[i];
if (l1<=r1){
ans+=r1-l1+1;
// cout<<l1<<' '<<r1<<endl;
}
}
cout<<ans*2;
}
cout<<endl;
return 0;
}