当前位置:网站首页>[number theory] divisor
[number theory] divisor
2022-07-06 11:04:00 【Nathan Qian】
Try division to find the divisor
subject
explain
- Because divisors appear in pairs , So you just need to i*i<=x
- prevent x It's a total square , One more number is recorded . Therefore, special deposit is required x/i Conditions
Code segment
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
vector<int>get_divisors(int x)
{
vector<int>ans;
for(int i=1;i*i<=x;i++)
{
if(x%i==0)
{
ans.push_back(i);
if(i!=x/i)ans.push_back(x/i);
}
}
sort(ans.begin(),ans.end());
return ans;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int x;cin>>x;
vector<int>ans=get_divisors(x);
for(auto x:ans)cout<<x<<' ';
cout<<endl;
}
return 0;
}
Find the number of divisors
subject
explain
- According to the above theorem , We should factorize each number , Then find the sum of prime factors
- be aware 1 Although it is a divisor , But the combination result is only 1 Kind of , So it's not in the scope
- about ans The multiplication modulus of cannot be written as ans*=x%mod, It can only be written as ans=ans*x%mod
Code segment
#include<iostream>
#include<unordered_map>
const int mod=1e9+7;
using namespace std;
unordered_map<int,int>primes;
int main()
{
int n;cin>>n;
while(n--)
{
int x;cin>>x;
for(int i=2;i*i<=x;i++)
{
if(x%i==0)
{
while(x%i==0)
{
primes[i]++;
x/=i;
}
}
}
if(x>1)primes[x]++;
}
long long ans=1;
for(auto it=primes.begin();it!=primes.end();it++)
{
ans=ans*(1+it->second)%mod;
}
cout<<ans%mod<<endl;
}
The sum of the approximations
subject
explain
- Here, please a1^α1 Sum of divisors of , It is obvious that there can be algebraic theorems
- Multiplication principle , It can be understood as the sum of each power combination of each prime number
- Select a number in each bracket and multiply it to exactly equal one of the divisors
- This does not repeat the choice of accumulation , That is, the sum of approximations
- When finding the sum of divisors of prime numbers , For the accumulation of proportional series
- The simple formula is
int t( frequency ) ,x( base number ),sum( and )
while(t--)
{
sum=sum*x+1;
}
Code segment
#include<iostream>
#include<unordered_map>
const int mod=1e9+7;
using namespace std;
int main()
{
int t;cin>>t;
unordered_map<int,int>primes;
while(t--)
{
int x;cin>>x;
for(int i=2;i*i<=x;i++)
{
if(x%i==0)
{
while(x%i==0)
{
primes[i]++;
x/=i;
}
}
}
if(x>1)primes[x]++;
}
long long sum=1;
for(auto it=primes.begin();it !=primes.end();it++)
{
long long tmp=1;
int t=it->second;
while(t--)
{
tmp=(tmp*it->first+1)%mod;
}
sum=sum*tmp%mod;
// Although it can guarantee tmp No more than mod, But if sum*tmp It is likely to be greater than mod
}
cout<<sum<<endl;
}
greatest common divisor
subject
explain
- Mathematical proof of Euclidean algorithm
- 【 number theory 】 Euclid algorithm _nathanqian123 The blog of -CSDN Blog
#include<iostream>
using namespace std;
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
int main()
{
int t;cin>>t;
while(t--)
{
int a,b;
cin>>a>>b;
cout<<gcd(a,b)<<endl;
}
}
边栏推荐
- [Thesis Writing] how to write function description of jsp online examination system
- Ansible practical Series III_ Task common commands
- Did you forget to register or load this tag 报错解决方法
- NPM an error NPM err code enoent NPM err syscall open
- Remember the interview algorithm of a company: find the number of times a number appears in an ordered array
- API learning of OpenGL (2004) gl_ TEXTURE_ MIN_ FILTER GL_ TEXTURE_ MAG_ FILTER
- Copie maître - esclave MySQL, séparation lecture - écriture
- Invalid default value for 'create appears when importing SQL_ Time 'error reporting solution
- 安全测试涉及的测试对象
- frp内网穿透那些事
猜你喜欢
Swagger, Yapi interface management service_ SE
CSDN blog summary (I) -- a simple first edition implementation
连接MySQL数据库出现错误:2059 - authentication plugin ‘caching_sha2_password‘的解决方法
MySQL19-Linux下MySQL的安装与使用
图片上色项目 —— Deoldify
Django运行报错:Error loading MySQLdb module解决方法
02-项目实战之后台员工信息管理
API learning of OpenGL (2003) gl_ TEXTURE_ WRAP_ S GL_ TEXTURE_ WRAP_ T
安装numpy问题总结
Windows cannot start the MySQL service (located on the local computer) error 1067 the process terminated unexpectedly
随机推荐
Ansible practical series I_ introduction
Ansible实战系列二 _ Playbook入门
A brief introduction to the microservice technology stack, the introduction and use of Eureka and ribbon
MySQL20-MySQL的数据目录
A trip to Macao - > see the world from a non line city to Macao
报错解决 —— io.UnsupportedOperation: can‘t do nonzero end-relative seeks
Windows下安装MongDB教程、Redis教程
Have you mastered the correct posture of golden three silver four job hopping?
Timestamp with implicit default value is deprecated error in MySQL 5.6
Postman uses scripts to modify the values of environment variables
基于apache-jena的知识问答
Mysql21 user and permission management
Global and Chinese market of transfer switches 2022-2028: Research Report on technology, participants, trends, market size and share
API learning of OpenGL (2003) gl_ TEXTURE_ WRAP_ S GL_ TEXTURE_ WRAP_ T
Some notes of MySQL
++Implementation of I and i++
安全测试涉及的测试对象
MySQL18-MySQL8其它新特性
There are three iPhone se 2022 models in the Eurasian Economic Commission database
Ansible实战系列一 _ 入门