当前位置:网站首页>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;
}
边栏推荐
- A brief history of deep learning (II)
- stm32F407-------SPI通信
- [force buckle]41 Missing first positive number
- 【JokerのZYNQ7020】AXI_EMC。
- Configuring the stub area of OSPF for Huawei devices
- 【批处理DOS-CMD命令-汇总和小结】-跳转、循环、条件命令(goto、errorlevel、if、for[读取、切分、提取字符串]、)cmd命令错误汇总,cmd错误
- mongodb客户端操作(MongoRepository)
- threejs图片变形放大全屏动画js特效
- 第七篇,STM32串口通信编程
- Leetcode(547)——省份数量
猜你喜欢
Part VI, STM32 pulse width modulation (PWM) programming
5种不同的代码相似性检测,以及代码相似性检测的发展趋势
[yolov5 6.0 | 6.1 deploy tensorrt to torch serve] environment construction | model transformation | engine model deployment (detailed packet file writing method)
深度学习之线性代数
【批处理DOS-CMD命令-汇总和小结】-跳转、循环、条件命令(goto、errorlevel、if、for[读取、切分、提取字符串]、)cmd命令错误汇总,cmd错误
Configuring OSPF basic functions for Huawei devices
[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
Linear algebra of deep learning
[牛客] [NOIP2015]跳石头
. Bytecode structure of class file
随机推荐
深度学习之环境配置 jupyter notebook
迈动互联中标北京人寿保险,助推客户提升品牌价值
深度学习简史(一)
第四篇,STM32中断控制编程
Dell Notebook Periodic Flash Screen Fault
Leetcode(547)——省份数量
新手如何入门学习PostgreSQL?
[batch dos-cmd command - summary and summary] - string search, search, and filter commands (find, findstr), and the difference and discrimination between find and findstr
Advanced learning of MySQL -- basics -- basic operation of transactions
随时随地查看远程试验数据与记录——IPEhub2与IPEmotion APP
[batch dos-cmd command - summary and summary] - view or modify file attributes (attrib), view and modify file association types (Assoc, ftype)
【YoloV5 6.0|6.1 部署 TensorRT到torchserve】环境搭建|模型转换|engine模型部署(详细的packet文件编写方法)
Cause of handler memory leak
深入探索编译插桩技术(四、ASM 探秘)
Chapter II proxy and cookies of urllib Library
Web project com mysql. cj. jdbc. Driver and com mysql. jdbc. Driver differences
[牛客] B-完全平方数
ZYNQ移植uCOSIII
Deep learning environment configuration jupyter notebook
STM32开发资料链接分享