A. Little C Loves 3 I Codeforces Round #511 (Div. 2) 数学
Posted dybala21
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了A. Little C Loves 3 I Codeforces Round #511 (Div. 2) 数学相关的知识,希望对你有一定的参考价值。
Little C loves number ?3? very much. He loves all things about it.
Now he has a positive integer nn. He wants to split nn into 3 positive integers a,b,ca,b,c, such that a+b+c=na+b+c=n and none of the 3 integers is a multiple of 3. Help him to find a solution.
A single line containing one integer nn (3≤n≤10^9) — the integer Little C has.
Print 3 positive integers a,b,c in a single line, such that a+b+c=n and none of them is a multiple of 3
It can be proved that there is at least one solution. If there are multiple solutions, print any of them.
3
1 1 1
233
77 77 79
题意分析:
这题是一个比较单纯的数学题目,给你一个数n,你需要把他分解成3个数,,并且这3个数都不是3的倍数。
这题我想的是根据数的素数分解原理,因为每个数都可以表示成素数相乘。所以对于N,
如果N的素因子中没有3,那么我们另外两个数只要相加等于3的倍数,那么就一定是满足的。
如果N的素因子中有3,那么此时,3应该还有个最大幂指数t,并且3的t次幂是N的一个因子。现在就是对3的t次幂的分解。假设 b = N/(3^t)
对3的t次幂分解成3个不被3整除的数还是比较简单的,因为是3的次幂,所以肯定可以分解成3个3的(t-1)次幂,那么 其中任意两个数减去1,另外一个数加上1就满足了,再把这3个数都乘以b即满足。
代码:
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int N;
while(~scanf("%d", &N))
{
int cnt = 1;
if(N%3 != 0) //N不是3的倍数
{
printf("%d %d %d
", 1, 2, N-3);
continue;
}
while(N%3 == 0) //提取N中3的t次幂因子。
{
cnt*=3;
N/=3;
}
int a, b, c, d;
d = cnt/3;
if(d%3==0)
{
a = (d-1)*N;
b = (d+2)*N;
c = (d-1)*N;
}
else //d==1
{
a = b = c = d*N;
}
printf("%d %d %d
", a, b, c);
}
return 0;
}
以上是关于A. Little C Loves 3 I Codeforces Round #511 (Div. 2) 数学的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #511 Div2 D. Little C Loves 3 II
A. DZY Loves Chessboard1200 / 思维
A. DZY Loves Chessboard1200 / 思维