http://codeforces.com/problemset/problem/992/C

题意:

给你两个数x,k,k代表有k+1个月,x每个月可以增长一倍,增长后的下一个月开始时x有50%几率减1,增长k+1个月后结果是每种情况的总和除以种数。

题目要求的是增长k+1个月后的结果。

我们根据第三个样例可以推出他的增长过程

    3

  6    5

12  11  10  9

|      |     |   |

24    22   20  18

从这个推导我们容易得出最后得到的每种情况构成一个等差数列,公差为2

结果是:(2*n-1)*2k+1

注意特判0的情况,0的时候答案是0,直接输出

另外求2的次方的时候用快速幂,注意取余

 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <sstream>
const int INF=0x3f3f3f3f;
typedef long long LL;
const int mod=1e9+;
//const double PI=acos(-1);
#define Bug cout<<"---------------------"<<endl
const int maxm=1e6+;
const int maxn=1e5+;
using namespace std; LL POW(LL a,LL b )
{
LL ans = ;
a = a % mod;
while(b)
{
if( b % == )
ans = ( ans * a ) % mod;
a = ( a * a ) % mod;
b /= ;
}
return ans;
} int main()
{
LL n,k;
scanf("%lld %lld",&n,&k);
LL ans=;
if(n!=)
{
n=n%mod;
ans=(((*n-)*POW(,k)+mod)%mod++mod)%mod;
}
printf("%d\n",ans);
return ;
}

CodeForces 992C Nastya and a Wardrobe(规律、快速幂)的更多相关文章

  1. CF思维联系– CodeForces -CodeForces - 992C Nastya and a Wardrobe(欧拉降幂+快速幂)

    Nastya received a gift on New Year - a magic wardrobe. It is magic because in the end of each month ...

  2. Codeforces 992C Nastya and a Wardrobe (思维)

    <题目链接> 题目大意: 你开始有X个裙子 你有K+1次增长机会 前K次会100%的增长一倍 但是增长后有50%的机会会减少一个 给你X,K(0<=X,K<=1e18), 问你 ...

  3. codeforces 677C C. Vanya and Label(组合数学+快速幂)

    题目链接: C. Vanya and Label time limit per test 1 second memory limit per test 256 megabytes input stan ...

  4. Codeforces Round #536 (Div. 2) F 矩阵快速幂 + bsgs(新坑) + exgcd(新坑) + 欧拉降幂

    https://codeforces.com/contest/1106/problem/F 题意 数列公式为\(f_i=(f^{b_1}_{i-1}*f^{b_2}_{i-2}*...*f^{b_k} ...

  5. ACM-ICPC 2018 焦作赛区网络预赛 G. Give Candies (打表找规律+快速幂)

    题目链接:https://nanti.jisuanke.com/t/31716 题目大意:有n个孩子和n个糖果,现在让n个孩子排成一列,一个一个发糖果,每个孩子随机挑选x个糖果给他,x>=1,直 ...

  6. CodeForces - 598A Tricky Sum (数学,快速幂的运用)

    传送门: http://codeforces.com/problemset/problem/598/A A. Tricky Sum time limit per test 1 second memor ...

  7. HDU 5793 A Boring Question (找规律 : 快速幂+逆元)

    A Boring Question 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5793 Description Input The first l ...

  8. noip-2006普及组-数列- 【模拟-找规律-快速幂】

    链接:https://ac.nowcoder.com/acm/contest/153/1047 来源:牛客网 题目描述 给定一个正整数k( ≤ k ≤ ),把所有k的方幂及所有有限个互不相等的k的方幂 ...

  9. Codeforces 514E Darth Vader and Tree 矩阵快速幂

    Darth Vader and Tree 感觉是个很裸的矩阵快速幂, 搞个100 × 100 的矩阵, 直接转移就好啦. #include<bits/stdc++.h> #define L ...

随机推荐

  1. PC端页面适应不同的分辨率的方法 (转载)

    原文地址:https://blog.csdn.net/fengzhen8023/article/details/81281117 上周完成一个PC端的项目,对于我这样的小白来说,这个项目里面最大的问题 ...

  2. zabbix监控oracle之orabbix安装

    zabbix服务器安装配置 zabbixserver中安装该软件 mkdir /opt/orabbix cp orabbix-1.2.3.zip /opt/orabbix cd /opt/orabbi ...

  3. 常用ES6-ES10知识点总结

    在工作中我们会常用到的一些es6-es10的一些特性还记得多少,今天就让我们重新复习一遍 ES6语法 1.Let 1.let声明的变量具有块级作用域, { let a = 1 } console.lo ...

  4. linux提交代码到github

    1.首先你得注册个github账户 .... 2.新建项目(可以选择私有或者公开的) 3.上述github代码仓库建立好了 ,就回到自己的linux服务器 3.1  在自己的项目目录里 qi 3.1. ...

  5. linux下的hashpump安装及使用

    hashpump是linux上的一个进行hash长度拓展攻击的工具,安装过程如下: git clone https://github.com/bwall/HashPump apt-get instal ...

  6. python期末复习—列表

    列表:列表元素需用逗号分隔,放在方括号里,如:list=['Q',15];元素类型可以是数字,单个字符,字符串,列表.字符串和字符需要用单引号引起来. 访问列表:print(列表名[0])访问第一个元 ...

  7. 尝试用kotlin做一个app(一)

    1.先添加一下anko库 依赖:implementation "org.jetbrains.anko:anko:$anko_version" 版本:ext.anko_version ...

  8. SpringBootStarter种类

    Name Description spring-boot-starter 核心starter, 包括auto-configuration支持, logging和YAML 支持 spring-boot- ...

  9. Codeforces Round #599 (Div. 2) Tile Painting

    题意:就是给你一个n,然后如果  n mod | i - j | == 0  并且 | i - j |>1 的话,那么i 和 j 就是同一种颜色,问你最大有多少种颜色? 思路: 比赛的时候,看到 ...

  10. 使用classList和dataset实现tab切换

    显示效果: 代码实现: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...