ural1682 Crazy Professor
Crazy Professor
Memory limit: 64 MB
- b + a · a ≡ 0 (mod k),
- a + b · b ≡ 0 (mod k),
where k is some parameter.
Input
Output
Sample
input | output |
---|---|
2 |
5 |
Notes
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=2e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,k,t,p[maxn],now[maxn];
vi mo[maxn];
int find(int x)
{
return p[x]==x?x:p[x]=find(p[x]);
}
int main()
{
int i,j;
scanf("%d",&k);
rep(i,,maxn-)p[i]=i;
for(i=;;i++)
{
ll q=((ll)i*i/k+)*k;
while((j=q-(ll)i*i)<i)
{
int x=find(j),y=find(i);
if(x==y)return *printf("%d\n",i);
else p[x]=y;
now[j]=i;
q+=k;
}
q=(ll)(i/k+)*k;
for(int x:mo[(q-i)%k])
{
if(now[x]==i)continue;
int y=find(x),r=find(i);
if(y==r)return *printf("%d\n",i);
else p[y]=r;
}
mo[(ll)i*i%k].pb(i);
}
//system("Pause");
return ;
}
ural1682 Crazy Professor的更多相关文章
- 1682. Crazy Professor(并查集)
1628 加了些数论知识 先看下剩余类的概念 一个整数被正整数n除后,余数有n种情形:0,1,2,3,…,n-1,它们彼此对模n不同余.这表明,每个整数恰与这n个整数中某一个对模n同余.这样一来,按 ...
- URAL 1682 Crazy Professor (并查集)
[题目链接] http://acm.timus.ru/problem.aspx?space=1&num=1682 [题目大意] 给出k,从1开始不断地加一并把这个数写在黑板上,如果写上的数字和 ...
- DevOps is dirty work - CI drives you crazy
一直很想谈谈Continuous Integration(CI),持续集成. 就在不久前一次朋友聚会上,一个刚刚跳槽到一家创业公司的朋友跟我抱怨说他们没有CI,没有code review,要做点事太累 ...
- Here's to the crazy ones.
Here's to the crazy ones. The misfits. The rebels. The troublemakers. The round pegs in the square h ...
- Urban Planning and Public Health - Reflection on Professor Webster's article in Urban Planning Forum
1. General review. Professor Webster published this article in Urban Planning Forum, one of the top ...
- [poj3378] Crazy Thairs (DP + 树状数组维护 + 高精度)
树状数组维护DP + 高精度 Description These days, Sempr is crazed on one problem named Crazy Thair. Given N (1 ...
- [poj1200]Crazy Search(hash)
Crazy Search Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26713 Accepted: 7449 Descrip ...
- Light OJ 1393 Crazy Calendar (尼姆博弈)
C - Crazy Calendar Time Limit:4000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Su ...
- THE ARCHITECTURE OF COMPLEXITY HERBERT A. SIMON* Professor of Administration, Carnegie Institute of Technology (Read April 26, 1962)
THE ARCHITECTURE OF COMPLEXITY HERBERT A. SIMON* Professor of Administration, Carnegie Institute of ...
随机推荐
- spring 框架的 @Autowired 和 @Resource 两种注解的区别
最开始做项目时,依赖注入用到的注解都是 J2EE 的 @Resource,那时还根本不了解 spring 有 @Autowired.心塞. 前两天想到估计有很多刚开始学习 java 的童鞋可能对这两个 ...
- JavaScript在智能手机上的应用-判断是否为移动浏览器
-------------------- <script type="text/javascript"> var userAgent = navi ...
- A - 娜娜梦游仙境系列——诡异的钢琴
A - 娜娜梦游仙境系列——诡异的钢琴 Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Othe ...
- text-size-adjust的值为100% 代替值 none
iPhone 横屏默认会放大文字,设置text-size-adjust会解决这个问题 一般用text-size-adjust:none 但建议用100%代替none text-size-adjust: ...
- 用 gulp.spritesmith 自动化雪碧图
一.安装nodejs之后,要设置两个环境变量 在 计算机右击属性---高级系统设置---高级---环境变量 打开窗口 新建2个环境变量,它们的值分别是nodejs根目录下的node_modules路径 ...
- IE11中的F12无效的问题
最近做的一个项目中,h5中的video标签IE11在有的机器上兼容,有的机器上不兼容,很是让人头疼.将IE卸载后重装又发现最新的IE11中F12开发者工具失效.面对F12失效的问题,具体解决办法如下: ...
- 一个字符串搜索的Aho-Corasick算法
Aho和Corasick对KMP算法(Knuth–Morris–Pratt algorithm)进行了改进,Aho-Corasick算法(Aho-Corasick algorithm)利用构建树,总时 ...
- Android ADT安装时卡在Calculating requirements and dependencies
AndroidSDK及Eclipse安装都很顺利,但是在Eclipse下安装ADT插件时,先采用点击Help->installnew software->Add...,无论输入https: ...
- SQL中的左连接与右连接有什么区别,点解返回值会不同?(转)
例子,相信你一看就明白,不需要多说 A表(a1,b1,c1) B表(a2,b2) a1 b1 c1 a2 b2 01 数学 95 01 张三 02 语文 90 02 李四 03 英语 80 04 王五 ...
- WNDCLASS 窗口类结构
Windows 的窗口总是基于窗口类来创建的,窗口类同时确定了处理窗口消息的窗口过程(回调函数). 在创建应用程序窗口之前,必须调用 RegisterClass 函数来注册窗口类.该函数只需要一个参数 ...