当前位置:网站首页>Informatics Olympiad YBT 1171: factors of large integers | 1.6 13: factors of large integers
Informatics Olympiad YBT 1171: factors of large integers | 1.6 13: factors of large integers
2022-07-07 01:02:00 【Jun Yi_ noip】
【 Topic link 】
ybt 1171: The factor of a large integer
OpenJudge NOI 1.6 13: The factor of a large integer
【 Topic test site 】
1. High precision
Investigate : High precision die low precision
Explanation of high-precision calculation
【 Their thinking 】
First treat the numbers involved in the operation as low precision numbers , To solve this problem , It's not hard to write code :
int main()
{
int k, c;
cin >> c;
bool hasK = false;
for(int k = 2; k <= 9; ++k)
{
if(c % k == 0)
{
cout << k << ' ';
hasK = true;
}
}
if(hasK == false)
cout << "none";
return 0;
}
In this question ,c Is a high-precision number ,k The scope is 2~9, It is still a low precision number . Then just put c%k==0
Rewritten as high precision die low precision , To solve the problem .
【 Solution code 】
solution 1: function + Array
#include<bits/stdc++.h>
using namespace std;
#define N 35
// Convert a character array to a number array The number array starts from 1 Position to len Location , Save the numbers from low to high , The first 0 Position saves the number of digits
void toNum(char s[], int a[])
{
a[0] = strlen(s);
for(int i = 1; i <= a[0]; ++i)
a[i] = s[a[0] - i] - '0';
}
// High precision die low precision
int Mod(int a[], int b)
{
int x = 0;
for(int i = a[0]; i >= 1; --i)
x = (x * 10 + a[i]) % b;
return x;
}
int main()
{
int n, k, c[N] = {
};
char s[N];
bool hasK = false;
cin >> s;
toNum(s, c);
for(k = 2; k <= 9; ++k)
{
if(Mod(c, k) == 0)
{
cout << k << ' ';
hasK = true;
}
}
if(hasK == false)
cout << "none";
return 0;
}
solution 2: Overloaded operator in class
#include <bits/stdc++.h>
using namespace std;
#define N 35
struct HPN
{
int a[N];// Array of numbers
HPN()
{
memset(a, 0, sizeof(a));
}
HPN(char s[])
{
memset(a, 0, sizeof(a));
int len = strlen(s);
for(int i = 0; i < len; ++i)
a[len - i] = s[i] - '0';
a[0] = len;
}
int operator % (int b) // High precision die low precision
{
int x = 0;
for(int i = a[0]; i >= 1; --i)
x = (x * 10 + a[i]) % b;
return x;
}
};
int main()
{
char s[N];
cin >> s;
HPN c(s);// High precision digital c
bool hasK = false;
for(int k = 2; k <= 9; ++k)
{
if(c % k == 0)// High precision die low precision
{
cout << k << ' ';
hasK = true;
}
}
if(hasK == false)
cout << "none";
return 0;
}
边栏推荐
- In rails, when the resource creation operation fails and render: new is called, why must the URL be changed to the index URL of the resource?
- 浅谈测试开发怎么入门,如何提升?
- 集合(泛型 & List & Set & 自定义排序)
- Explain in detail the matrix normalization function normalize() of OpenCV [norm or value range of the scoped matrix (normalization)], and attach norm_ Example code in the case of minmax
- Linear algebra of deep learning
- 深度学习简史(二)
- Building a dream in the digital era, the Xi'an station of the city chain science and Technology Strategy Summit ended smoothly
- 线段树(SegmentTree)
- ActiveReportsJS 3.1中文版|||ActiveReportsJS 3.1英文版
- Part 7: STM32 serial communication programming
猜你喜欢
【批處理DOS-CMD命令-匯總和小結】-字符串搜索、查找、篩選命令(find、findstr),Find和findstr的區別和辨析
New feature of Oracle 19C: automatic DML redirection of ADG, enhanced read-write separation -- ADG_ REDIRECT_ DML
pyflink的安装和测试
[batch dos-cmd command - summary and summary] - string search, search, and filter commands (find, findstr), and the difference and discrimination between find and findstr
[batch dos-cmd command - summary and summary] - jump, cycle, condition commands (goto, errorlevel, if, for [read, segment, extract string]), CMD command error summary, CMD error
windows安装mysql8(5分钟)
Five different code similarity detection and the development trend of code similarity detection
Stm32f407 ------- SPI communication
Telerik UI 2022 R2 SP1 Retail-Not Crack
Part IV: STM32 interrupt control programming
随机推荐
Batch obtain the latitude coordinates of all administrative regions in China (to the county level)
tensorflow 1.14指定gpu运行设置
Periodic flash screen failure of Dell notebook
New feature of Oracle 19C: automatic DML redirection of ADG, enhanced read-write separation -- ADG_ REDIRECT_ DML
STM32开发资料链接分享
Advanced learning of MySQL -- basics -- multi table query -- joint query
View remote test data and records anytime, anywhere -- ipehub2 and ipemotion app
一行代码实现地址信息解析
threejs图片变形放大全屏动画js特效
Summary of being a microservice R & D Engineer in the past year
Slow database query optimization
Part VI, STM32 pulse width modulation (PWM) programming
深度学习简史(一)
随时随地查看远程试验数据与记录——IPEhub2与IPEmotion APP
Three methods to realize JS asynchronous loading
Cause of handler memory leak
What is time
How to get started and improve test development?
Return to blowing marshland -- travel notes of zhailidong, founder of duanzhitang
build. How to configure the dependent version number in the gradle file