题目:

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.

Input

A single line containing one integer nn (3≤n≤10^9) — the integer Little C has.

Output

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.

Examples
input
3
output
1 1 1
input
233
output
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\n", 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\n", a, b, c); }
return 0;
}

  

A. Little C Loves 3 I Codeforces Round #511 (Div. 2) 【数学】的更多相关文章

  1. Codeforces Round #511 (Div. 2)

    Codeforces Round #511 (Div. 2) #include <bits/stdc++.h> using namespace std; int n; int main() ...

  2. 2018.9.21 Codeforces Round #511(Div.2)

    只写了AB,甚至还WA了一次A题,暴露了蒟蒻的本质=.= 感觉考的时候有好多正确或和正解有关的思路,但是就想不出具体的解法或者想的不够深(长)(怕不是过于鶸) 话说CF的E题怎么都这么清奇=.= A. ...

  3. Codeforces Round #511 (Div. 2):C. Enlarge GCD(数学)

    C. Enlarge GCD 题目链接:https://codeforces.com/contest/1047/problem/C 题意: 给出n个数,然后你可以移除一些数.现在要求你移除最少的数,让 ...

  4. Codeforces Round #511 (Div. 2)-C - Enlarge GCD (素数筛)

    传送门:http://codeforces.com/contest/1047/problem/C 题意: 给定n个数,问最少要去掉几个数,使得剩下的数gcd 大于原来n个数的gcd值. 思路: 自己一 ...

  5. Codeforces Round #511 (Div. 1) C. Region Separation(dp + 数论)

    题意 一棵 \(n\) 个点的树,每个点有权值 \(a_i\) .你想砍树. 你可以砍任意次,每次你选择一些边断开,需要满足砍完后每个连通块的权值和是相等的.求有多少种砍树方案. \(n \le 10 ...

  6. Codeforces Round #511 Div.1 A Div.2 C

    嗯切一题走人很开心. gzy-50分比我还惨. 题意:有n个数,去掉尽量少的数使得剩下数的gcd变大. 首先把这n个数都除以gcd,就变成了去掉尽量少的数使得gcd不等于1. 可以枚举一个质数,然后统 ...

  7. C. Enlarge GCD Codeforces Round #511 (Div. 2)【数学】

    题目: Mr. F has nn positive integers, a1,a2,…,an. He thinks the greatest common divisor of these integ ...

  8. B. Cover Points Codeforces Round #511 (Div. 2)【数学】

    题目: There are nn points on the plane, (x1,y1),(x2,y2),…,(xn,yn)(x1,y1),(x2,y2),…,(xn,yn). You need t ...

  9. Codeforces Round #511 (Div. 2) C. Enlarge GCD

    题目链接 题目就是找每个数的最小素因子,然后递归除,本来没啥问题,结果今天又学习了个新坑点. 我交了题后,疯狂CE,我以为爆内存,结果是,我对全局数组赋值, 如果直接赋值,会直接在exe内产生内存,否 ...

随机推荐

  1. EF添加和修改

    (1)//添加操作 public bool addDate() { try { //声明上下文 a_context = new AEntities(); //声明数据模型实体 //执行代码时候会先验证 ...

  2. 434. Number of Segments in a String 字符串中的单词个数

    [抄题]: Count the number of segments in a string, where a segment is defined to be a contiguous sequen ...

  3. Luogu 3206 [HNOI2010]城市建设

    BZOJ 2001 很神仙的cdq分治 先放论文的链接   顾昱洲_浅谈一类分治算法 我们考虑分治询问,用$solve(l, r)$表示询问编号在$[l, r]$时的情况,那么当$l == r$的时候 ...

  4. Entity Framework 6.0 Tutorials(5):Command Interception

    Interception: Here, you will learn how to intercept EF when it executes database commands. EF 6 prov ...

  5. word 2013如何从某一页开始插入页码

    把光标移入要插入页面的最前面 插入分页符 在要插入页码的页脚双击打开页脚设计 取消页脚和前面页眉的链接 插入页码

  6. IOException while loading persisted sessions: java.io.EOFException

    运行eclipse启动服务器的时候,出现了IOException while loading persisted sessions: java.io.EOFException报错.本以为是代码修改出现 ...

  7. 制作百度地图离线JavaScript API加载本地瓦片地图

    全面介绍,请看下列介绍地址,改写目前最新版本的百度V2.0地图,已全面实现离线操作,能到达在线功能的95%以上 http://api.jjszd.com:8081/apituiguang/gistg. ...

  8. RequireJS 主入口加载模块经常会加载失败的问题

    在接入requirejs时,在main入口遇到了这样的问题,使用jquery,刷新10次页面会有3-4次加载失败,找不到$符号等等 require.config({ 'baseUrl': './mod ...

  9. sqlServer DataReader与DataSet的区别

    sqlServer   DataReader与DataSet的区别 从以下这几个方面比较: 1.与数据库连接: DataReader:面向连接,只读,只进,只能向前读,读完数据就断开连接: DataS ...

  10. 【题解】 UVa11292 The Dragon of Loowater

    题目大意: 你的王国里有一条n个头的恶龙,你希望雇佣一些骑士把它杀死(即砍掉所有头).村里有m个骑士可以雇佣,一个能力值为x的骑士可以砍掉恶龙一个直径不超过x的头,且需要支付x个金币.如何雇佣骑士才能 ...