题意:1e6~1e6+5000之间任意两个之间同余方程组的解。余数为欧拉函数。

解题关键:线性筛预处理,扩展中国剩余定理暴力求解。

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<iostream>
#define MAXN 1005002
using namespace std;
typedef long long ll;
ll x,y,r[MAXN],m[MAXN],n; //将求素数和欧拉函数值都线性解出
int prime[MAXN];//保存素数
bool vis[MAXN];//初始化
int phi[MAXN];//欧拉函数
void Lphisieve(int n){
int cnt=;
for(int i=;i<n;i++){
if(!vis[i]){
prime[cnt++]=i;
phi[i]=i-;// if p is prime,then phi[i]=i-1
}
for(int j=;j<cnt&&i*prime[j]<n;j++){
int k=i*prime[j];
vis[k]=true;
if(i%prime[j]==){
phi[k]=phi[i]*prime[j];
break;
}
else phi[k]=phi[i]*(prime[j]-);
}
}
} ll extgcd(ll a,ll b,ll &x,ll &y){
ll d=a;
if(b) d=extgcd(b,a%b,y,x),y-=a/b*x;
else x=,y=;
return d;
}
ll excrt(int n,ll *m,ll *r){
ll M=m[],pre=r[],d;//a是模数
for(int i=;i<n;i++){
d=extgcd(M,m[i],x,y);
if((pre-r[i])%d!=) return -;
x=(pre-r[i])/d*x%m[i];
pre-=x*M;
M=M/d*m[i];//lcm
pre%=M;
}
return (pre%M+M)%M;
}
int main(){
Lphisieve();
ll sum=;
for(ll i=;i<;i++){
m[]=i,r[]=phi[i];
for(ll j=i+;j<;j++){
m[]=j,r[]=phi[j];
ll t=excrt(,m,r);
if(t==-) t=;
sum+=t;
}
}
printf("%lld\n",sum);
}

[pe531]Chinese leftovers的更多相关文章

  1. 使用MySQL数据库将汉字转换成拼音的一个C语言小程序

    环境: mysql:mysql-5.1.65 centos:centos 6.5 编译命令: gcc -o chinesetopinyin chinesetopinyin.c -L/usr/lib/m ...

  2. 英语阅读——Speaking Chinese in America

    这篇文章是<新视野大学英语>第四册的第五单元的文章,第一遍英语阅读完后对比中文,发现自己对作者的观点理解有些出入.作者反对的是认为中国说话客套而美国人直接的观点,利用自己的经历表达了中文也 ...

  3. CTRL-Space always toggles Chinese IME (Windows 7、10)

    一.window占用了ctrl+空格的快捷键,影响开发工具的只能提示的使用. 二.解决方式: Go to Start > Type in regedit and start it (打开运行输入 ...

  4. OpenCascade Chinese Text Rendering

    OpenCascade Chinese Text Rendering eryar@163.com Abstract. OpenCascade uses advanced text rendering ...

  5. NetSuite Chinese Finance Reports

    NetSuite has a strong report customization application. The standard finance reports has a different ...

  6. Chinese economic influence in North Korea

    Where this new investment is being targeted is also interesting雄性禿 . "If you look at the econom ...

  7. Configure Amazon RDS mysql to store Chinese Characters

    Configure Amazon RDS mysql to store Chinese Characters https://dev.mysql.com/doc/refman/5.7/en/chars ...

  8. Chinese culture

      文房四宝 笔墨纸砚是中国古代文人书房中必备的宝贝,被称为“文房四宝”.用笔墨书写绘画在 中国可追溯到五千年前.秦(前221---前206)时已用不同硬度的毛和竹管制笔:汉代(前206—公元220) ...

  9. XidianOJ 1182 Chinese Paladin – Qi’s troubles

    题目描述 As we all know, Xiahou Jinxuan (Chinese Paladin 5 Prequel's protagonist) and Yue Jinzhao (Chine ...

随机推荐

  1. 关于mongodb创建索引的一些经验总结(转)

    查看语句执行计划: explain() 在mongodb3+版本后输出格式发生改变: 详情参见:https://docs.mongodb.com/v3.0/reference/method/curso ...

  2. python书写日志的重要性?

    转自:https://blog.csdn.net/weixin_43063753/article/details/82899395 程序为什么要写日志?#为了能够在程序在运行过程中记录错误,方便维护, ...

  3. dm层 集市层 四层 Build a multi-level data strategy

    集市层 四层模型 ODS(临时存储层) MID(中间层) DM(数据集市层) APP(应用层) http://www.datamartist.com/data-warehouse-vs-data-ma ...

  4. 图床QAQ

  5. 【docker】学习笔记一:制作自己的centos6.9镜像

    前言: 最近开始研究docker,在这里做一个记录. 本来开始想用centos7系列做镜像,毕竟是最新版本的centos,但是centos7有一个严重的bug,就是正常启动的镜像不能使用systemc ...

  6. before-request , after-request

    1 . flask的中间件 1)@app.before_request     # 请求进入视图函数之前,类似于django中间件的request_process 2)@app.after_reque ...

  7. 郝健: Linux内存管理学习笔记-第2节课【转】

    本文转载自:https://blog.csdn.net/juS3Ve/article/details/80035753 摘要 slab./proc/slabinfo和slabtop 用户空间mallo ...

  8. 51Nod 1225 余数之和 —— 分区枚举

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1225 1225 余数之和  基准时间限制:1 秒 空间限制:1 ...

  9. 维特比算法(Viterbi)

    维特比算法(Viterbi) 维特比算法 编辑 维特比算法是一种动态规划算法用于寻找最有可能产生观测事件序列的-维特比路径-隐含状态序列,特别是在马尔可夫信息源上下文和隐马尔可夫模型中.术语“维特比路 ...

  10. openfire build(2)

    InterceptorManager PluginManager openfire 插件的中servlet 在web-custom.xml 中的配置 url 一定要小写,访问时不区别大写小 否则404 ...