DAY 6

数论 模拟 数论 数论?

A

Decription:

C ( n , m ) = P ( n , m ) m ! = n ! m ! ( n − m ) ! C(n,m)=\frac{P(n,m)}{m!}=\frac{n!}{m!(n-m)!} C(n,m)=m!P(n,m)=m!(nm)!n!,判断其结果奇偶性

Input

输入要求

Output

> **输出要求**

Sample Input:

2
7 3
8 2

Sample Output:

1
0

思路
求啥找啥,就把阶乘中的2的个数预处理出来,之后看一下如果分子的2的数量大于分母那么其一定为偶数,反之则为奇数。

代码

#include<iostream>
#include<cstdio>
#define N 10000000
using namespace std;
int t,n,m,sum[N+1];
int div(int x)
{
	int res=0;
	while(x)
	{
		if(!(x&1)) res++;
		else break;
		x>>=1;
	}
	return res;
}
void qread(int &x) {
    int f = 1; x = 0; char s = getchar();
    while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
    while (s >= '0' && s <= '9') { x = x*10+(s-'0'); s = getchar(); }
    x = x*f;
}
int main()
{
	qread(t);
	for(int i=1;i<=1e7;i++) sum[i]=sum[i-1]+div(i);
	while(t--)
	{
	  qread(n),qread(m);
	  if(sum[n]>sum[m]+sum[n-m]) putchar('0');
	  else putchar('1');
	  putchar('\n');
	}
    return 0;	
} 

B

Decription:

有10个小球,小球的编号从0~9。
初始状态按照从左到右编号为0,1,2,3…9的顺序摆在了桌子上,
有一个长度大小为n的操作序列。
操作序列的每一行表示一次操作都有两个非负整数a,b,
表示本次操作将会交换位置a,b的2个小球(下标从0编号)
一共有m次询问,
每次询问时,将杯子中的小球重置为初始状态。
给出[li,ri],连续从操作li进行到ri,
连续操作完后依次回答位置0到9,对应位置的小球编号。

Input

给出n,m
接下来n行,给出第i个操作交换小球的位置a ,b
接下来m行对应m个询问,给出li,ri,回答询问

Output

m行,每行对应一个询问

Sample Input:

5 3
0 1
1 2
2 3
0 1
9 0
1 5
5 5
3 5

Sample Output:

9 1 3 0 4 5 6 7 8 2
9 1 2 3 4 5 6 7 8 0
9 0 3 2 4 5 6 7 8 1

Data Constraint

30%:2<=n,m<=10000
100%:2<=n,m<=100000,0<=a,b<=9,1<=li<=ri<=n

思路:
这个相同就是大大滴水题,首先我们先预处理出以一为起点到n的所有操作呈现出的结果,然后后面询问直接一一对应即可。

代码

#include<iostream>
#include<cstdio>
#define N 100000
using namespace std;
int n,m;
int q[N+1][11],t[11],x,y,l,r;
void qread(int &x) {
    int f = 1; x = 0; char s = getchar();
    while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
    while (s >= '0' && s <= '9') { x = x*10+(s-'0'); s = getchar(); }
    x = x*f;
}

void qwrite(int x) {
    if (x < 10) { putchar('0'+x); return; }
    qwrite(x/10);
    putchar('0'+x%10);
} 
int main()
{
    qread(n),qread(m);
    for(int i=0;i<=9;i++) q[0][i]=i;
    for(int i=1;i<=n;i++) 
    {
    	qread(x),qread(y);
    	for(int j=0;j<=9;j++) q[i][j]=q[i-1][j];
    	swap(q[i][x],q[i][y]);
	}
    for(int i=1;i<=m;i++)
    {
    	qread(l),qread(r);
    	for(int j=0;j<=9;j++) t[j]=q[l-1][j];
    	for(int j=0;j<=9;j++) //下标 
    	for(int k=0;k<=9;k++)
    	{
    		if(t[k]==q[r][j]) 
    		{
    			qwrite(k),putchar(' ');
    			break;
			}
		}
		printf("\n");
	}
    return 0;	
} 

C

Decription:

对于一个正整数N,若x满足,(N-0.5x)/(N-x)为正整数,则x为N的幸运数。
给出一个N,求出[1,N-1]所有N的幸运数,
先回答个数,在将幸运数从小到大输出。

Input

第一行一个正整数N

Output

第一个整数为cnt,表示有多少个满足的幸运数,后面cnt个数,表示满足的幸运数

Sample Input:

9

Sample Output:

2 6 8

Data Constraint

对于30%的数据,N<= 1 0 8 10^8 108.
对于100%的数据,N<= 1 0 14 10^{14} 1014

思路:一眼就知道,要推公式
N − 0.5 x N − x \frac{N-0.5x}{N-x} NxN0.5x

-------------------------------------------------------------- 两 边 同 乘 2 两边同乘2 2----------------------------------------------------------

2 N − x 2 N − 2 x \frac{2N-x}{2N-2x} 2N2x2Nx
-------------------------------------------然后根据题目的意思,设一个约数y,使-----------------------------------------

2 y ( N − x ) = 2 N − x 2y(N-x)=2N-x 2y(Nx)=2Nx

----------------------------------------------------------------拆解一下-------------------------------------------------------------

2 y ( N − x ) = N + N − x 2y(N-x)=N+N-x 2y(Nx)=N+Nx

------------------------------------------------------------------移项-----------------------------------------------------------------

( 2 y − 1 ) ( N − x ) = N (2y-1)(N-x)=N (2y1)(Nx)=N
那么2y-1就是N的约数,设2y-1等于d,其必须满足d%2==1。其余就不解释了,看代码吧(公式推的好像和代码不一样?)懒得改了。qaq,有思路就好了

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define ll long long
#define N 3000000
using namespace std;
ll n,ans[N+1],len;
int main()
{
    scanf("%lld",&n);
    for(ll i=1;i*i<=n;i++)
	{
	  	if(n%i) continue;
	  	ll a1=i,a2=n/i;
	  	ll ans1=(n/a1)*(a1-1),ans2=(n/a2)*(a2-1);
		if(a1&1&&!(ans1&1)&&ans1>=1&&ans1<n) ans[++len]=ans1;
		if(a2&1&&!(ans2&1)&&ans2>=1&&ans2<n&&a1!=a2) ans[++len]=ans2;  
	} 
	sort(ans+1,ans+len+1);
	printf("%lld ",len);
	for(int i=1;i<=len;i++) printf("%lld ",ans[i]);
    return 0;	
} 

Decription:

对于一个正整数N,若x满足,(N-0.5x)/(N-x)为正整数,则x为N的幸运数。
给出一个N,求出[1,N-1]所有N的幸运数,
先回答个数,在将幸运数从小到大输出。

Input

第一行一个正整数N

Output

第一个整数为cnt,表示有多少个满足的幸运数,后面cnt个数,表示满足的幸运数

Sample Input:

9

Sample Output:

2 6 8

Data Constraint

对于30%的数据,N<= 1 0 8 10^8 108.
对于100%的数据,N<= 1 0 14 10^{14} 1014

D

Decription:

Input

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-oNT0E70m-1629428573977)(http://10.156.31.134/admin/upload/images/13%282%29.png#pic_center)]

Output
>**第一个整数为cnt,表示有多少个满足的幸运数,后面cnt个数,表示满足的幸运数**

Sample Input:

5 5
1 10 2 6 2
Ask 1 3
Quant 1 2 5
Ask 1 3
Quant 1 4 5
Ask 4 5

Sample Output:

my_dog
stoorz
Stoorz

Data Constraint

> **对于30%的数据,N<=.对于100%的数据,N<=**

思路
在这里插入图片描述

代码

#include<iostream>
#include<cstdio> 
#include<cmath>
#include<algorithm>
#include<vector>
#define N 100000
#define ll long long
#define limit 46
using namespace std;
int n,m,l,r,num,a[5000000],len,f[N+1],lit[N+1]; 
string s;
vector<int> t[N+1];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1,aa;i<=n;i++) 
    	scanf("%d",&aa),t[i].push_back(aa),f[i]=i+1,lit[i]=1;
	while(m--)
	{
		cin>>s;
		if(s=="Ask") 
		{
			len=0;
			bool flag=0;
			scanf("%d%d",&l,&r);
			for(int j=l;j<=r;j++) 
			{
				if(lit[j]>limit)
		        {
		        	printf("stoorz\n");
		        	flag=1;
		        	break;
				}
			    for(int k=0;k<lit[j];k++) 
				{
					a[++len]=t[j][k];
					if(len>limit) 
					{
						flag=1;
						printf("stoorz\n");
						break;
					}
				}
				if(flag) break;
			 } 
			if(flag) continue;
			sort(a+1,a+len+1);
			for(int j=1;j<=len-2;j++)
			if(a[j]+a[j+1]>a[j+2])
			{
				flag=1;
				break;
			}
			if(flag) printf("stoorz\n");
			else printf("my_dog\n");
		}
		else
		{
			scanf("%d%d%d",&l,&r,&num);
			for(int j=l;j<=r;j=f[j])
			{
				if(lit[j]>limit) continue;
				t[j].push_back(num),lit[j]++;
				if(lit[j]>limit) f[j-1]=f[j];
			}
		}
	}
	return 0;
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\protocol\Parser.js:437 throw err; // Rethrow non-MySQL errors ^ Error: secretOrPrivateKey must have a value at module.exports [as sign] (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\jsonwebtoken\sign.js:107:20) at Query.<anonymous> (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\router_handler\2user.js:49:26) at Query.<anonymous> (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\Connection.js:526:10) at Query._callback (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\Connection.js:488:16) at Sequence.end (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\protocol\sequences\Sequence.js:83:24) at Query._handleFinalResultPacket (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\protocol\sequences\Query.js:149:8) at Query.EofPacket (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\protocol\sequences\Query.js:133:8) at Protocol._parsePacket (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\protocol\Protocol.js:291:23) at Parser._parsePacket (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\protocol\Parser.js:433:10) at Parser.write (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\protocol\Parser.js:43:10) Node.js v18.12.1
06-08

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值