CF基础数学题

CF基础数学题

B. Divisors of Two Integers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Recently you have received two positive integer numbers x
and y. You forgot them, but you remembered a shuffled list containing all divisors of x (including 1 and x) and all divisors of y (including 1 and y). If d is a divisor of both numbers x and y at the same time, there are two occurrences of d

in the list.

For example, if x=4
and y=6 then the given list can be any permutation of the list [1,2,4,1,2,3,6]. Some of the possible lists are: [1,1,2,4,6,3,2], [4,6,1,1,2,3,2] or [1,6,3,2,4,1,2]

.

Your problem is to restore suitable positive integer numbers x
and y

that would yield the same list of divisors (possibly in different order).

It is guaranteed that the answer exists, i.e. the given list of divisors corresponds to some positive integers x
and y

.
Input

The first line contains one integer n
(2≤n≤128) — the number of divisors of x and y

.

The second line of the input contains n
integers d1,d2,…,dn (1≤di≤104), where di is either divisor of x or divisor of y. If a number is divisor of both numbers x and y

then there are two copies of this number in the list.
Output

Print two positive integer numbers x
and y

— such numbers that merged list of their divisors is the permutation of the given list of integers. It is guaranteed that the answer exists.
Example
Input
Copy

10
10 2 8 1 2 4 1 20 4 5

Output
Copy

20 8


找出最大的那个数(所求的一个数),遍历把他的因子去掉那么剩下来的最大的数就是所求的另一个数。

#include<bits/stdc++.h>
using namespace std;
int a[130];
int main()
{
	int n;
	scanf("%d",&n);
	int maxx=0;
	unordered_map<int ,int >mp;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		mp[a[i]]++;
		maxx=max(a[i],maxx);
	}
	int maxx2=0;
	for(int i=0;i<n;i++)
	{
		if(maxx%a[i]==0)
		{
			mp[a[i]]--;
		}
		if(mp[a[i]]>0)
		{
			maxx2=max(maxx2,a[i]);
		}
	}
	printf("%d %d\n",maxx,maxx2);
 } 

A. Ksusha and Array
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Ksusha is a beginner coder. Today she starts studying arrays. She has array a1, a2, …, an, consisting of n positive integers.

Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number!
Input

The first line contains integer n (1 ≤ n ≤ 105), showing how many numbers the array has. The next line contains integers a1, a2, …, an (1 ≤ ai ≤ 109) — the array elements.
Output

Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn’t exist, print -1.

If there are multiple answers, you are allowed to print any of them.
Examples
Input
Copy

3
2 2 4

Output
Copy

2

Input
Copy

5
2 1 3 1 6

Output
Copy

1

Input
Copy

3
2 3 5

Output
Copy

-1

#include<bits/stdc++.h>
using namespace std;
int a[100010];
int main()
{
	int n;
	scanf("%d",&n);
	int ans=-1;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		
	}
	sort(a,a+n);
	if(a[0]==1) 
	{
		printf("1\n");
		return 0; 
	} 
	int ff=1;
	for(int i=1;i<n;i++)
	{
		if(a[i]%a[0]!=0)
		{
			printf("-1");
			ff=0;
			break;
		}
	}
	if(ff)
	{
		printf("%d",a[0]);
	}
	
 } 
B. Square Difference
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Alice has a lovely piece of cloth. It has the shape of a square with a side of length a
centimeters. Bob also wants such piece of cloth. He would prefer a square with a side of length b centimeters (where b<a

). Alice wanted to make Bob happy, so she cut the needed square out of the corner of her piece and gave it to Bob. Now she is left with an ugly L shaped cloth (see pictures below).

Alice would like to know whether the area of her cloth expressed in square centimeters is prime. Could you help her to determine it?
Input

The first line contains a number t
 (1≤t≤5

) — the number of test cases.

Each of the next t
lines describes the i-th test case. It contains two integers a and b (1≤b<a≤1011)

 — the side length of Alice's square and the side length of the square that Bob wants.
Output

Print t
lines, where the i-th line is the answer to the i

-th test case. Print "YES" (without quotes) if the area of the remaining piece of cloth is prime, otherwise print "NO".

You can print each letter in an arbitrary case (upper or lower).
Example
Input
Copy

4
6 5
16 13
61690850361 24777622630
34 33

Output
Copy

YES
NO
NO
YES

Note

The figure below depicts the first test case. The blue part corresponds to the piece which belongs to Bob, and the red part is the piece that Alice keeps for herself. The area of the red part is 62−52=36−25=11

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool isprime(ll x)
{
	if(x==1) return 0;
	for(int i=2;i<=sqrt(x);i++)
	{
		if(x%i==0)
		{
			return 0;
		}
	}
	return 1;
}
int main()
{
	int tt;
	scanf("%d",&tt);
	while(tt--)
	{
		ll a,b;
		scanf("%lld%lld",&a,&b);
		if(a-b!=1) 
		{
			printf("NO\n");
			continue;
		}
		ll ans=a+b;
		if(isprime(ans)) printf("Yes\n");
		else printf("NO\n");
	}
}

似乎时间复杂度更小的方法(适用对于范围在int内的数)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool isprime(ll x)
{
	if(x==2||x==3||x==5) return 1;
	if(x%2==0||x%3==0||x%5==0||x==1) return 0;
	ll c=7,a[8]={4,2,4,2,4,6,2,6};
	while(c*c<=x)
	{
		for(auto i:a)
		{
			if(x%c==0)
			{
				return 0;
			}
			c+=i;
		}
	}
	return 1;
}
int main()
{
	int tt;
	scanf("%d",&tt);
	while(tt--)
	{
		ll a,b;
		scanf("%lld%lld",&a,&b);
		if(a-b!=1) 
		{
			printf("NO\n");
			continue;
		}
		ll ans=a+b;
		if(isprime(ans)) printf("Yes\n");
		else printf("NO\n");
	}
}

A. I’m bored with life
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It’s well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom!

Leha came up with a task for himself to relax a little. He chooses two integers A and B and then calculates the greatest common divisor of integers “A factorial” and “B factorial”. Formally the hacker wants to find out GCD(A!, B!). It’s well known that the factorial of an integer x is a product of all positive integers less than or equal to x. Thus x! = 1·2·3·…·(x - 1)·x. For example 4! = 1·2·3·4 = 24. Recall that GCD(x, y) is the largest positive integer q that divides (without a remainder) both x and y.

Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren’t you?
Input

The first and single line contains two integers A and B (1 ≤ A, B ≤ 109, min(A, B) ≤ 12).
Output

Print a single integer denoting the greatest common divisor of integers A! and B!.
Example
Input
Copy

4 3

Output
Copy

6

Note

Consider the sample.

4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n,m;
	cin>>n>>m;
	ll ans=1;
	for(int i=2;i<=min(n,m);i++)
	{
		ans*=i;
	}
	printf("%lld",ans);
}

组合数

C. The World is a Theatre
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

There are n boys and m girls attending a theatre club. To set a play “The Big Bang Theory”, they need to choose a group containing exactly t actors containing no less than 4 boys and no less than one girl. How many ways are there to choose a group? Of course, the variants that only differ in the composition of the troupe are considered different.

Perform all calculations in the 64-bit type: long long for С/С++, int64 for Delphi and long for Java.
Input

The only line of the input data contains three integers n, m, t (4 ≤ n ≤ 30, 1 ≤ m ≤ 30, 5 ≤ t ≤ n + m).
Output

Find the required number of ways.

Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.
Examples
Input
Copy

5 2 5

Output
Copy

10

Input
Copy

4 3 5

Output
Copy

3

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll  get_c( int n,int  m)
{
    ll c[100][100];
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=m;j++)
		{
			if(j==0||j==i)
			{
				c[i][j]=1;
			}else 
			{
				c[i][j]=c[i-1][j-1]+c[i-1][j];
			}
		 } 
	}
	return c[n][m];
}

int main()
{
	int  n,m,t;
	cin>>n>>m>>t;
	ll ans=0;
	for(int  i=4;i<=t-1;i++)
	{
		ll a=get_c(n,i);
		
			ans+=a*get_c(m,t-i);
	}
	cout<<ans<<endl;
}

B. Proper Nutrition
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya has n burles. One bottle of Ber-Cola costs a burles and one Bars bar costs b burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars.

Find out if it’s possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly n burles.

In other words, you should find two non-negative integers x and y such that Vasya can buy x bottles of Ber-Cola and y Bars bars and x·a + y·b = n or tell that it’s impossible.
Input

First line contains single integer n (1 ≤ n ≤ 10 000 000) — amount of money, that Vasya has.

Second line contains single integer a (1 ≤ a ≤ 10 000 000) — cost of one bottle of Ber-Cola.

Third line contains single integer b (1 ≤ b ≤ 10 000 000) — cost of one Bars bar.
Output

If Vasya can’t buy Bars and Ber-Cola in such a way to spend exactly n burles print «NO» (without quotes).

Otherwise in first line print «YES» (without quotes). In second line print two non-negative integers x and y — number of bottles of Ber-Cola and number of Bars bars Vasya should buy in order to spend exactly n burles, i.e. x·a + y·b = n. If there are multiple answers print any of them.

Any of numbers x and y can be equal 0.
Examples
Input
Copy

7
2
3

Output
Copy

YES
2 1

Input
Copy

100
25
10

Output
Copy

YES
0 10

Input
Copy

15
4
8

Output
Copy

NO

Input
Copy

9960594
2551
2557

Output
Copy

YES
1951 1949

Note

In first example Vasya can buy two bottles of Ber-Cola and one Bars bar. He will spend exactly 2·2 + 1·3 = 7 burles.

In second example Vasya can spend exactly n burles multiple ways:

buy two bottles of Ber-Cola and five Bars bars;
buy four bottles of Ber-Cola and don't buy Bars bars;
don't buy Ber-Cola and buy 10 Bars bars. 

In third example it’s impossible to but Ber-Cola and Bars bars in order to spend exactly n burles.

水题

#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
int main()
{
	ll n,a,b;
	cin>>n>>a>>b;
	for(int i=0;i<=n/a;i++)
	{
		if((n-a*i)%b==0)
		{
			printf("YES\n");
			printf("%d %d\n",i,(n-a*i)/b);
			return 0;
		}
	}
	printf("NO\n");
}
<think>好的,我现在需要帮用户解决如何在Codeforces上复制题目描述的问题。用户之前提到了关于Hacks页面的Verdict,现在转向了复制题面的需求。首先,我要回想自己知道的Codeforces平台的功能,有没有直接复制的方法? 根据经验,Codeforces的题目页面通常不允许直接选中文字复制,特别是数学公式和特殊格式的内容,因为它们可能以图片或LaTeX渲染的方式呈现。用户可能遇到了无法直接复制的情况,需要寻找解决方法。 接下来,我需要考虑用户可能的实际需求。用户可能是想复制题目内容到本地保存,或者用于翻译、做题分析等。这时候,可能需要替代方法,比如查看HTML源码、使用浏览器扩展或者第三方工具。 然后,回忆之前的引用内容。引用1提到了codeforces better插件停止维护,用户可能尝试过插件但失败了。引用2和4是关于解题方法的,可能与当前问题关联不大,但引用3提到了题面的输出格式,比如大小写不敏感,这可能说明题面中的特定格式需要注意。 现在需要给出几种方法:1. 直接选中复制,尽管可能部分内容无法复制;2. 查看页面源码,从HTML中提取文本;3. 使用控制台脚本提取内容;4. 第三方工具或浏览器扩展,但要注意codeforces better已经不可用,可能需要其他替代插件;5. 手动处理,比如截图OCR识别。 还需要注意用户提到的codeforces better插件不可用,所以可能需要推荐其他方法,比如源码查看或脚本。同时,提醒用户注意比赛规则,避免在比赛中违规复制内容,可能涉及作弊。 最后,确保回答结构清晰,分点说明,并给出步骤和注意事项。同时,生成相关问题,如处理数学公式、比赛中的复制限制等,帮助用户进一步了解。</think>在 Codeforces 平台中,**直接复制题目描述**的功能受限于页面设计,但可通过以下方法实现: --- ### 一、**基础复制方法** 1. **部分文本直接选中复制** - 对于**纯文字段落**(如题目背景、输入输出说明),可直接用鼠标选中后复制 - **限制**:数学公式、特殊符号(如 $\leq$, $\sum$)可能无法正确复制为文本格式,会变成 LaTeX 代码片段或乱码 [^3] 2. **通过开发者工具提取** 1. 在题目页面按 `F12` 打开浏览器开发者工具 2. 切换到 **Elements** 标签,搜索包含题目内容的 `div`(通常类名为 `problem-statement`) 3. 右键该元素选择 **Copy -> Copy outerHTML**,粘贴到文本编辑器后手动清理 HTML 标签 ```html <!-- 示例结构 --> <div class="problem-statement"> <div class="header"><h2>A. Example Problem</h2></div> <div class="content"><p>This is the problem description...</p></div> </div> ``` --- ### 二、**进阶工具与技巧** 1. **浏览器控制台脚本** 运行以下 JavaScript 代码提取纯文本(需在题目页面执行): ```javascript console.log(document.querySelector('.problem-statement').innerText); ``` - 输出内容可直接全选复制 - **优势**:自动去除 HTML 标签,保留段落结构 2. **第三方工具** - **CF-Predictor**(替代已停更的 Codeforces Better 插件):支持题目页面增强功能 - **Tampermonkey 脚本**:可自定义脚本提取题目描述(需注意脚本安全性)[^1] 3. **OCR 识别** 对无法复制的数学公式: - 使用截图工具(如 Snipaste)截取公式区域 - 通过 **Mathpix** 等 OCR 工具转换为 LaTeX 代码(例如将 $\int_{a}^{b} f(x)dx$ 转换为可编辑格式) --- ### 三、**注意事项** 1. **比赛规则限制** - 在 **比赛进行期间**,大量复制题目描述可能触发反作弊检测 - 建议仅复制必要部分(如关键约束条件)用于本地调试 [^4] 2. **格式优化建议** - 粘贴后手动调整 LaTeX 公式格式(如将 `$$x^2$$` 改为 `$x^2$` 以适配 Markdown 或其他编辑器) - 使用正则表达式批量替换多余空格或换行符 --- ### 四、**操作示例** 以题目 [Codeforces Round 920 (Div. 3) Problem A](https://codeforces.com/contest/1921/problem/A) 为例: 1. 按 `F12` 打开开发者工具 2. 在 **Console** 标签粘贴上述 JavaScript 代码 3. 复制输出的文本内容至本地文件: ``` A. Square time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: standard output ... ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值