一些签到题

[NOIP2012 普及组] 质因数分解 - 洛谷

唯一分解定理:一个数能且只能分解为一组质数的乘积。

因为题目给定的n一定能被拆成两个质数的乘积,因此遍历一遍2-n,只要找到的约数就是这俩质数之一。

#include<bits/stdc++.h>
using ll=long long;
using PII=std::pair<double,double>;

#define fir first
#define sec second

const int N=2e5+10;
void solve()
{
	int n;
	std::cin>>n;
	
	for(int i=2;i<=n;i++)
	{
		if(n%i==0)
        {
          std::cout<<n/i;
          break;
        }
	}
	
}
signed main()
{
	std::ios::sync_with_stdio(0);
	std::cin.tie(0);
	
	int t=1;
	//std::cin>>t;;
	while(t--)
	{
		solve();
	} 
	return 0;
}

信友队-猴子吃桃

比如一开始有n个桃子,吃了n/2+1,最后剩下n/2-1个桃子。

突破点在于这题最后只剩下一个桃子,所以倒数第二天一定是4个桃子,倒数第三天一定是10个桃子,因此这就是个递推的数列。

#include<bits/stdc++.h>
using ll=long long;
using PII=std::pair<double,double>;

#define fir first
#define sec second

const int N=2e5+10;

int f[N];
void solve()
{
	int n;
	std::cin>>n;
	
	ll sum=0;
	int now=1;
	for(int i=1;i<n;i++)
	{
		//sum+=now;
		now=(now+1)*2;
	}
	std::cout<<now;
}
signed main()
{
	std::ios::sync_with_stdio(0);
	std::cin.tie(0);
	
	int t=1;
	//std::cin>>t;;
	while(t--)
	{
		solve();
	} 
	return 0;
}

信友队-回型矩阵

#include<stdio.h>
 
int a[100][100];
int n;
void Visit(int n)
{
    int p=1,q=n;
    int count=0;
 
    while(count<n*n)
    {
        for(int i=p;i<=q;i++)//从上面开始赋值
            a[p][i]=++count;
 
        for(int i=p+1;i<=q;i++)//从右边开始赋值
            a[i][q]=++count;
 
        for(int i=q-1;i>=p;i--)//从下面开始赋值
            a[q][i]=++count;
 
        for(int i=q-1;i>=p+1;i--)
            a[i][p]=++count;
            p++;
            q--;
    }
}
void Print(int n)
{
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
            printf("%d ",a[i][j]);
        
        printf("\n");
    }
}
int main()
{
    scanf("%d",&n);
    Visit(n);
    Print(n);
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值