java实现 蓝桥杯 算法提高 Problem S4: Interesting Numbers 加强版
1 问题描述
Problem Description
We call a number interesting, if and only if:
1. Its digits consists of only 0, 1, 2 and 3, and all these digits occurred at least once.
2. Inside this number, all 0s occur before any 1s, and all 2s occur before any 3s.
Therefore, the smallest interesting number according to our definition is 2013. There are two more interseting number of 4 digits: 2031 and 2301.
Your task is to calculate the number of interesting numbers of exactly n digits. As the answer might be very large, you only need to output the answer modulo 1000000007.
Input Format
The input has one line consisting of one positive integer n (4 ≤ n ≤ 10^15).
Output Format
The output has just one line, containing the number of interesting numbers of exactly n digits, modulo 1000000007.
Input Sample
4
Output Sample
3
2 解决方案
本题主要考查数学组合数推理化简,具体思考过程如下:

推导过程,在草稿纸上推导了一下:

import java.util.Scanner;
public class Main {
static long n;
static long mul, ans, res;
static long monum = 1000000007;
private static long cal(long n) {
if (n == 1)
return 2;
long num = cal(n / 2);
num = num * num % monum;
if (n % 2 == 1)
num = num * 2 % monum;
return num;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner reader = new Scanner(System.in);
n = reader.nextLong();
if (n == 4)
System.out.println(3);
else {
n = n - 1;
res = (n % monum) * (n % monum);
res = ((res - 3 * n) % monum + monum) % monum;
n = n - 2;
mul = cal(n);
res = res * mul % monum;
n = n + 2;
res = (res + n) % monum;
System.out.println(res);
}
}
}
java实现 蓝桥杯 算法提高 Problem S4: Interesting Numbers 加强版的更多相关文章
- 算法笔记_093:蓝桥杯练习 Problem S4: Interesting Numbers 加强版(Java)
目录 1 问题描述 2 解决方案 1 问题描述 Problem Description We call a number interesting, if and only if: 1. Its d ...
- Java实现 蓝桥杯 算法提高 进攻策略加强(暴力)
试题 算法提高 进攻策略加强 问题描述 植物大战僵尸这款游戏中,还有一个特别的玩儿法:玩家操纵僵尸进攻植物. 首先,僵尸有m种(每种僵尸都是无限多的),玩家可以选择合适的僵尸来进攻.使用第i种僵尸需要 ...
- Java实现 蓝桥杯 算法提高 小X的购物计划
试题 算法提高 小X的购物计划 问题描述 小X打算去超市shopping.小X没什么钱,只有N元.超市里有M种物品,每种物品都需要money,在小X心中有一个重要度.有的物品有无限件,有的物品只有几件 ...
- Java实现 蓝桥杯 算法提高 天天向上(DP)
试题 算法提高 天天向上 问题描述 A同学的学习成绩十分不稳定,于是老师对他说:"只要你连续4天成绩有进步,那我就奖励给你一朵小红花."可是这对于A同学太困难了.于是,老师对他放宽 ...
- Java实现 蓝桥杯 算法提高 欧拉函数(数学)
试题 算法提高 欧拉函数 问题描述 老师出了一道难题,小酱不会做,请你编个程序帮帮他,奖金一瓶酱油: 从1-n中有多少个数与n互质? |||||╭══╮ ┌═════┐ ╭╯让路║═║酱油专用车║ ╰ ...
- Java实现 蓝桥杯 算法提高 计算超阶乘(暴力)
试题 算法提高 计算超阶乘 问题描述 计算1*(1+k)(1+2k)(1+3k)-(1+n*k-k)的末尾有多少个0,最后一位非0位是多少. 输入格式 输入的第一行包含两个整数n, k. 输出格式 输 ...
- Java实现蓝桥杯 算法提高 线段和点
算法提高 线段和点 时间限制:1.0s 内存限制:256.0MB 提交此题 问题描述 有n个点和m个区间,点和区间的端点全部是整数,对于点a和区间[b,c],若a>=b且a<=c,称点a满 ...
- Java实现蓝桥杯-算法提高 P1003
算法提高 P1003 时间限制:1.0s 内存限制:256.0MB 作为一名网络警察,你的任务是监视电子邮件,看其中是否有一些敏感的关键词.不过,有些狡猾的犯罪嫌疑人会改变某些单词的字母顺序,以逃避检 ...
- Java实现蓝桥杯 算法提高 八皇后 改
**算法提高 8皇后·改** 时间限制:1.0s 内存限制:256.0MB 提交此题 问题描述 规则同8皇后问题,但是棋盘上每格都有一个数字,要求八皇后所在格子数字之和最大. 输入格式 一个8*8的棋 ...
随机推荐
- USACO 3.1 Contact
http://www.nocow.cn/index.php/Translate:USACO/contact 题目大意:给一个只含0和1的序列,统计每个子序列的重复次数,并按次数递减来输出 考虑子序列时 ...
- 「雕爷学编程」Arduino动手做(22)——8X8 LED点阵MAX7219屏
37款传感器与模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的.鉴于本人手头积累了一些传感器和模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里 ...
- 【Django】rest_framework 序列化自定义替换返回值
# 序列化设置 class PagerSerialiser(serializers.ModelSerializer): name = serializers.CharField(source=&quo ...
- linux常用命令---计划定时任务
计划定时任务(crontab) 存放定时任务的文件 /var/spool/cron systemctl status cron ps -ef|grep crond 检测crontab是否开机启动 sy ...
- [Asp.Net Core] Blazor WebAssembly - 工程向 - 如何在欢迎页面里, 预先加载wasm所需的文件
前言, Blazor Assembly 需要最少 1.9M 的下载量. ( Blazor WebAssembly 船新项目下载量测试 , 仅供参考. ) 随着程序越来越复杂, 引用的东西越来越多, ...
- mysql小白系列_14 线上故障分析与排错
1.重现故障5---线上执行update报错,并处理.(表结构和UPDATE语句自己构造,请给出详细步骤) 1)update故障出现ERROR 1206 (HY000): The total numb ...
- postman发送请求携带Cookie
相关步骤: 1.下载 Postman-Interceptor_v0.2.24.zip插件 2.解压下载好的插件,将其拖到应用配置中 3.复制Postman-Interceptor_v中的id地址 4. ...
- STM32F103出现CPU could not be halted问题的解决方案
问题描述: **JLink Warning: CPU could not be halted ***JLink Error: Can not read register 15 (R15) while ...
- Java术语
- ztree实用教程
首先导入ztree ztree是建立在jquery的基础上的 <link href="js/zTree_v3-master/css/zTreeStyle/zTreeStyle.css& ...