题意
读入一个N ,请将(2025-N)用a*b (a,b均为小于10的正整数)的形式来表示,并按照字典序大小从小到大输出所有方法
输出格式为 a x b (注意末尾要换行)
思路
数据比较水,可以直接双重
f
o
r
for
for循环通过。
如果是素数的话,可以提前判断一下。
代码
#include<bits/stdc++.h>
#include<cstring>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<map>
#define ll long long
using namespace std;
const int N=1e5+10;
const int M=2023;
const int inf=0x3f3f3f3f;
int n;
bool sushu(int x)
{
for(int i=2;i<=sqrt(x);i++)
{
if(x%i==0)return 0;
}
return 1;
}
int main()
{
scanf("%d",&n);
n=2025-n;
if(sushu(n)==1)
{
if(n==1)printf("1 x 1\n");
else printf("1 x %d\n%d x 1",n,n);
return 0;
}
for(int i=1;i<10;i++)
{
for(int j=1;j<10;j++)
{
if(i*j==n)
{
printf("%d x %d\n",i,j);
}
}
}
return 0;
}