01
Art Class
02
Graph Theory Class
consider adding points one by one, then if the newly added point x is a composite number, then it is connected to a certain factor, and the overall weight is increased by x; if x is a prime number, then it is connected to 2 and the overall value is increased Twice x. This is the optimal connection situation.
Min25 sieve to find the prefix sum of prime numbers within n+1, plus 2+3+4+...n+1.
#include <cstdio>
#include <cstring>
using namespace std;
const long long Nmax=10000000005ll;
const long long SQR=100005ll;
long long N,Ha,Haa,g[SQR*3],ans;
long long w[SQR*3],id1[SQR],id2[SQR],cnt;
long long f[SQR],P[SQR],SP[SQR],num;
void get_pri(long long Pmax)
{
num=0;
memset(f,0,sizeof(f));
for (long long i=2; i<=Pmax; i++)
{
if (!f[i])
{
P[++num]=i;
SP[num]=SP[num-1]+i;
}
for (long long j=1,k; j<=num && (k=i*P[j])<=Pmax; j++)
{
f[k]=1;
if (i%P[j]==0)
break;
}
}
}
void get_id()
{
cnt=0;
for (long long i=1,k; i<=N; )
{
k=N/i; //g[k] 是需要的,将 k 离散出来
w[++cnt]=k; //离散出的数中第 cnt 个为 k
if (k<=SQR)
id1[k]=cnt;
else
id2[N/k]=cnt;
i=N/k+1; //使 k 跳到往后使 N/k 加 1
}
}
inline int ID(long long x){
return (x<=SQR ? id1[x] : id2[N/x]);}
void get_g()
{
long long X;
for (int i=1; i<=cnt; i++) //dp初始化, 即 j=0 时 g[w][j] 等于2~w累加
{
g[i]=(w[i]+2)*(w[i]-1)/2;
}
for (int j=1; j<=num; j++)
{
for (int i=1; i<=cnt; i++)
{
if (P[j]*P[j]>w[i]) break;
//X=((g[ID(w[i]/P[j])]-SP[j-1])%Ha+Ha)%Ha;
X=g[ID(w[i]/P[j])]-SP[j-1];
g[i]=g[i]-P[j]*X;
//if (g[i]<0) g[i]=(g[i]%Ha+Ha)%Ha;
//if (g[i]>Ha) g[i]%=Ha;
}
}
}
int main()
{
long long T,n;
scanf("%lld",&T);
get_pri(SQR);
while(T--)
{
ans=0;
scanf("%lld%lld",&n,&Ha);
Haa=Ha*Ha;
N=n+1;
get_id();
get_g();
ans=g[ID(N)]%Ha;
ans=(ans+(n+3)%Ha*n%Ha*(Ha+1)/2%Ha)%Ha; //2+3+...+(n+1)
ans=(ans-4+Ha)%Ha;
printf("%lld\n",ans);
}
return 0;
}
/*
1
260136231 19260817
*/
03
Chess Class
04
Chess Class
05
Lunch
06
CCPC Training Class To cite a
few examples, I found that putting all the letters that appear the most at the beginning is the best situation.
#include <cstdio>
int T,a[30],ans;
char ch;
int main()
{
scanf("%d",&T);
ch='a'-5;
for (int kk=1; kk<=T; kk++)
{
for (int i=0; i<26; i++)
a[i]=0;
while (ch<'a' || ch>'z')
ch=getchar();
while (ch>='a' && ch<='z')
{
a[ch-'a']++;
ch=getchar();
}
ans=0;
for (int i=0; i<26; i++)
if (ans<a[i])
ans=a[i];
printf("Case #%d: %d\n",kk,ans);
}
return 0;
}
07
PE Class
08
Math Class
09
Reports
10
3x3 Convolution
This matrix multiplication image point is to buckle the upper left corner of K to the point (i, j) on A, and then assign the sum of the overlapping positions to the new point (i, j). If K is some If the position of some points exceeds A, ignore those positions of K (that is, multiply if you can multiply.)
Looking at the sample, you can guess that the answer is either output as-is or all 0s.
Think about when it is output as it is: only when the answer is "K only has a non-zero element in the upper left corner", it is output as it is.
If K is in other cases, is the answer 0: take the point in the lower right corner of A as a breakthrough, since the sum of K elements is 1, if K has non-zero elements in other places besides the upper left corner, then for the lower right corner of A After each multiplication, it will decrease, and it will decrease proportionally to 0. In this way, the points around the lower right corner of A will also keep decreasing, and so on, the entire A will eventually tend to 0 .
so problem solved. Pay attention to the format (space at the end of the line).
#include <cstdio>
int main()
{
//freopen("1.txt","w",stdout);
int T,n,f,a[1000][1000],b[10];
scanf("%d",&T);
while (T--)
{
f=0;
scanf("%d",&n);
for (int i=1; i<=n; i++)
for (int j=1; j<=n; j++)
scanf("%d",&a[i][j]);
for (int i=1; i<=9; i++)
{
scanf("%d",&b[i]);
f+=b[i];
}
if (b[1]==f && f>0)
{
for (int i=1; i<=n; i++)
{
for (int j=1; j<=n; j++)
{
if (j==n)
printf("%d",a[i][j]);
else
printf("%d ",a[i][j]);
}
printf("\n");
}
}
else
{
for (int i=1; i<=n; i++)
{
for (int j=1; j<=n; j++)
{
if (j==n)
printf("0");
else
printf("0 ");
}
printf("\n");
}
}
}
return 0;
}
11
Xor