[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;
}