当前位置:网站首页>[Blue Bridge Cup 2017 preliminary] buns make up
[Blue Bridge Cup 2017 preliminary] buns make up
2022-07-06 11:25:00 【%xiao Q】
subject
Title Description
Xiao Ming has breakfast in a bun shop almost every morning . This bun shop has N Grow steamer , Among them the first i The kind of steamer can put Ai A steamed bun
Each kind of steamer has a lot of steamers , It can be thought of as an infinite cage .
Whenever a customer wants to buy X A steamed bun , Uncle will choose some steamed buns , So that these cages happen to have X A steamed bun .
Let's say there are 3 Grow steamer , You can put 3、4 and 5 A steamed bun . When customers want to buy 11 A bun , Uncle will choose 2 Cage 3 One more 1 Cage 5 One of the ( It is also possible to elect 1 Cage 3 One more 2 Cage 4 One of the ).
Of course, sometimes uncle baozi can't figure out the quantity customers want to buy .
Let's say there are 3 Grow steamer , You can put 4、5 and 6 A steamed bun . And customers want to buy 7 A bun , Uncle can't make it out .
Xiao Ming wants to know how many kinds of numbers can't be found by Uncle baozi .
Input format
The first line contains an integer N.(1 <= N <= 100)
following N Each line contains an integer Ai.(1 <= Ai <= 100)
Output format
The output line contains an integer to represent the answer . If you can't figure out an infinite number , Output INF.
sample input Copy
2
4
5
sample output Copy
6
Data range and tips
For example , The uncountable number includes :1, 2, 3, 6, 7, 11.
analysis :
This problem needs to know a theorem , Euclidean theorem : For not completely 0 The integer of a,b So there must be integers x,y bring gcd(x,y) = a * x + b * y.
So we can assume that a * x + b * y = d, To make the equation solvable , that d % gcd(a, b) = 0 It is inevitable , If gcd(a,b) = 1, that d Can divide any number , That is to say a,b this 2 Any number can be divided by numbers ( But there can't be negative numbers in it , So there are some numbers that cannot be summed up ), On the contrary, we can't .
So the first step is to find the greatest common divisor of these numbers , If gcd = 1, Then how many numbers can't be summed up in the judgment , If gcd != 1, Then there must be countless kinds of numbers that can't be summed up , Direct output INF.
Reference code :
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <unordered_map>
#define LL long long
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define reps(i, a, b) for(int i = a; i < b; i++)
#define pre(i, a, b) for(int i = b; i >= a; i--)
using namespace std;
const int N = 10010, M = 110;
int f[N];
int a[N];
int main()
{
int n;
cin >> n;
int g = 0;
rep(i, 1, n)
{
cin >> a[i];
g = __gcd(g, a[i]);
}
if(g != 1)
{
puts("INF");
return 0;
}
rep(i, 1, n) f[a[i]] = 1;
rep(i, 1, n)
for(int j = 0; j + a[i]<= 10000; j++) // Here to 10000 It's a little metaphysical ( mathematics , No )
{
if(f[j]) f[j + a[i]] = 1;
}
int ans = 0;
rep(i, 1, 10000)
if(!f[i]) ans++;
cout << ans << endl;
return 0;
}
边栏推荐
- Asp access Shaoxing tourism graduation design website
- Case analysis of data inconsistency caused by Pt OSC table change
- L2-004 这是二叉搜索树吗? (25 分)
- MTCNN人脸检测
- Windows下安装MongDB教程、Redis教程
- Learning question 1:127.0.0.1 refused our visit
- 连接MySQL数据库出现错误:2059 - authentication plugin ‘caching_sha2_password‘的解决方法
- Software testing and quality learning notes 3 -- white box testing
- Number game
- [蓝桥杯2017初赛]包子凑数
猜你喜欢
Leetcode 461 Hamming distance
Pytorch基础
Basic use of redis
QT creator shape
Deoldify项目问题——OMP:Error#15:Initializing libiomp5md.dll,but found libiomp5md.dll already initialized.
When you open the browser, you will also open mango TV, Tiktok and other websites outside the home page
Reading BMP file with C language
Double to int precision loss
Face recognition_ recognition
02 staff information management after the actual project
随机推荐
neo4j安装教程
數據庫高級學習筆記--SQL語句
Install mongdb tutorial and redis tutorial under Windows
连接MySQL数据库出现错误:2059 - authentication plugin ‘caching_sha2_password‘的解决方法
Library function -- (continuous update)
Software I2C based on Hal Library
AcWing 1294. Cherry Blossom explanation
[Thesis Writing] how to write function description of jsp online examination system
软件测试与质量学习笔记3--白盒测试
快来走进JVM吧
TCP/IP协议(UDP)
QT creator specify editor settings
Mtcnn face detection
Summary of numpy installation problems
ES6 let 和 const 命令
In the era of DFI dividends, can TGP become a new benchmark for future DFI?
误删Path变量解决
项目实战-后台员工信息管理(增删改查登录与退出)
天梯赛练习集题解LV1(all)
Introduction and use of automatic machine learning framework (flaml, H2O)