#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
const int maxn=;
int prime[maxn];
bool not_prime[maxn];
int main()
{
int n,cnt=;
scanf("%d",&n);
memset(not_prime,,sizeof(not_prime));
not_prime[]=true;
for(int i=;i<=n;i++)
{
if(!not_prime[i])
prime[++cnt]=i;
for(int j=;j<=cnt;j++)
{
if(prime[j]*i>n) break;
not_prime[prime[j]*i]=true;
if(i%prime[j]==) break;
}
}
for(int i=;i<=cnt;i++)
printf("%d ",prime[i]);
return ;
} //线性筛
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
int x,y;
int exgcd(int a,int b)
{
if(!b)
{
x=;
y=;
return a;
}
else
{
int t;
int d=exgcd(b,a%b);
t=x;
x=y;
y=t-a/b*x;
return d;
}
}
int main()
{
int a,b;
scanf("%d%d",&a,&b);
exgcd(a,b);
// cout<<__gcd(a,b)<<endl;
cout<<x<<" "<<y<<endl;
return ;
} //扩展欧几里得
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
int gcd(int a,int b)
{
if(!b) return a;
else return gcd(b,a%b);
}
int lcm(int a,int b)
{
return a/gcd(a,b)*b;
}
int main()
{
int a,b;
scanf("%d%d",&a,&b);
cout<<gcd(a,b)<<" "<<lcm(a,b)<<endl;
return ;
} //gcd+lcm
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
int main()
{
long long n;
scanf("%lld",&n);
for(long long i=;i<=n;i++)
{
while(n!=i)
{
if(n%i==)
{
printf("%lld*",i);
n=n/i;
}
else break;
}
}
printf("%lld",n);
return ;
}
//分解质因数
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
int a[],mo[];
int gcd(int a,int b)
{
if(!b) return a;
else return gcd(b,a%b);
}
int lcm(int a,int b)
{
return a/gcd(a,b)*b;
}
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d%d",&a[i],&mo[i]);
int ans=,nowmo=;
for(int i=;i<=n;i++)
{
int other=a[i],othermo=mo[i];
if(othermo>nowmo)
{
swap(ans,other);
swap(nowmo,othermo);
}
while(ans%othermo!=other)
ans+=nowmo;
nowmo=lcm(nowmo,othermo);
}
printf("%d",ans);
}
//大数翻倍法

数论板子——来自Loi_black的更多相关文章

  1. 一些神奇的(优化)板子——来自Loi_black的博客

    deque<int>q; void spfa(int s) { ;i<=n;i++) d[i]=1e9; d[s]=; q.push_back(s); used[s]=; while ...

  2. Codeforces 1106F Lunar New Year and a Recursive Sequence (数学、线性代数、线性递推、数论、BSGS、扩展欧几里得算法)

    哎呀大水题..我写了一个多小时..好没救啊.. 数论板子X合一? 注意: 本文中变量名称区分大小写. 题意: 给一个\(n\)阶递推序列\(f_k=\prod^{n}_{i=1} f_{k-i}b_i ...

  3. CSP考前复习

    前言 因为loceaner太菜了,他什么东西都不会 所以他打算学一个东西就记录一下 不过因为他很菜,所以他不会写原理-- 而且,他希望在2019CSP之前不会断更 就酱紫,就是写给他自己的--因为他太 ...

  4. THUWC2019 GG记

    所以要什么时候才不会出现像这样的滚粗记呢? Day-?~Day-4 我也不清楚具体干了什么 不过学了很多东西,至少相对于去年还是个小菜鸡,今年已经变成大菜鸡了 Day-3~Day-1 几乎就是复习前面 ...

  5. CF1106F Lunar New Year and a Recursive Sequence

    题目链接:CF1106F Lunar New Year and a Recursive Sequence 大意:已知\(f_1,f_2,\cdots,f_{k-1}\)和\(b_1,b_2,\cdot ...

  6. NOIp2018停课刷题记录

    Preface 老叶说了高中停课但是初中不停的消息后我就为争取民主献出一份力量 其实就是和老师申请了下让我们HW的三个人听课结果真停了 那么还是珍惜这次机会好好提升下自己吧不然就\(AFO\)了 Li ...

  7. 洛谷——P1125 笨小猴

    P1125 笨小猴 题目描述 笨小猴的词汇量很小,所以每次做英语选择题的时候都很头疼.但是他找到了一种方法,经试验证明,用这种方法去选择选项的时候选对的几率非常大! 这种方法的具体描述如下:假设max ...

  8. noip2017爆炸记——题解&总结&反省(普及组+提高组)

    相关链接: noip2018总结 noip2017是我见过的有史以来最坑爹的一场考试了. 今年北京市考点有一个是我们学校,我还恰好被分到了自己学校(还是自己天天上课的那个教室),于是我同时报了普及提高 ...

  9. T1订正记-AC自动机-从树到图

    AC自动机已经足够棒了. 但是,好像有时还是要TLE的. 一般的AC自动还是比较好,如果在某些情况下还是会被卡掉,像是这个水题 考试的感觉 我看到这个题后,我清清楚楚的知道,这是个AC自动机+栈. 经 ...

随机推荐

  1. Kafka的架构

    1.Kafka整体架构    一个典型的Kafka集群中包含若干producer(可以是web前端产生的page view,或者是服务器日志,系统CPU.memory等),若干broker(Kafka ...

  2. 1.2 使用电脑测试MC20模块的GPS功能测试

    需要准备的硬件 MC20开发板 1个 https://item.taobao.com/item.htm?id=562661881042 GSM/GPRS天线 1根 https://item.taoba ...

  3. php 计算器的例子

    php实现的计算器的例子,代码如下: <html>     <head>         <title>PHP实现简单计算器-www.jbxue.com</t ...

  4. django-admin 设计User外键,设计model

    设置外键 class profile_user(AbstractBaseUser, PermissionsMixin): company = models.ForeignKey(Company, de ...

  5. Linux用户和用户组管理 用户管理相关命令

    用户添加命令 useradd 注意: 新添加的用户如果不设定密码是不能够登录系统的 命令格式: [root@localhost ~]#useradd [选项] 用户名 选项说明: 选项 选项说明 -u ...

  6. Django-Ajax进阶

    一.Ajax上传文件 1.form表单上传文件 文件和其他的数据类型不一样,是一个二进制的形式 Form上传文件的时候切记要加上:enctype="multipart/form-data&q ...

  7. 防止iframe被别的网站引用

    try{ top.location.hostname; if (top.location.hostname != window.location.hostname) { top.location.hr ...

  8. 适配iOS9问题汇总

    iOS 9适配过程中出现的问题,收集的链接资料供大家学习分享. http://wiki.mob.com/ios9-对sharesdk的影响(适配ios-9必读)/ http://www.cocoach ...

  9. Android LCD(一):LCD基本原理【转】

    本文转载自:http://blog.csdn.net/longxiaowu/article/details/24787597 关键词:Android LCD TFT 液晶 偏光片 彩色滤光片  背光 ...

  10. Cisco学习笔记

    目录 1. 路由 1.1 静态路由 1.2 动态路由 2. 访问控制列表 2.1 标准访问控制列表 2.2 扩展访问控制列表 2.3 命名访问控制列表 3. VLAN 3.1 基础知识 3.2 配置实 ...