poj_2773
题目的愿意非常easy。给你一个n,求在升序排列的情况下,第k个与之相互素的数。
解法:首先我们要知道gcd(b×t+a,b)=gcd(a。b),那么接下来就非常easy了。全部与之互素的数都是以phi(n),为周期的,所以暴力求解就可以。
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <cmath>
#include <vector>
using namespace std;
#define N 1000010
#define pi acos(-1.0)
#define inf 100000000
typedef int ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b){
if(b==0) return a;
else return gcd(b,a%b);
}
ll p[N];
int main(){
//freopen("in.txt","r",stdin);
ll n,k;
int e;
while(~scanf("%d%d",&n,&k)){
e=0;
for(int i=1;i<=n;i++){
if(gcd(i,n)==1)
p[++e]=i;
}
printf("%d\n",p[(k-1)%e+1]+(k-1)/e*n);
}
return 0;
}
poj_2773的更多相关文章
随机推荐
- [Luogu1119]采蘑菇
题目大意: 给你一个无向图,点i在时间t[i]之前是不存在的,有q组询问,问你时间为t时从x到y的最短路. 点的编号按出现的时间顺序给出,询问也按照时间顺序给出. 思路: Floyd. Floyd的本 ...
- Problem E: 十六进制转十进制
#include<stdio.h> int main(void) { ]; int sum,i; while(gets(str)!=NULL) { sum=; ;str[i]!='\0'; ...
- struts2和spring整合错误 org.springframework.beans.factory.BeanCreationException,已解决
先贴上错误 2018-8-16 23:41:10 org.springframework.context.support.ClassPathXmlApplicationContext prepareR ...
- Codeforces Beta Round #3 A. Shortest path of the king 水题
A. Shortest path of the king 题目连接: http://www.codeforces.com/contest/3/problem/A Description The kin ...
- WPF Interaction框架简介(一)——Behavior
在WPF 4.0中,引入了一个比较实用的库——Interactions,这个库主要是通过附加属性来对UI控件注入一些新的功能,除了内置了一系列比较好用的功能外,还提供了比较良好的扩展接口.本文这里简单 ...
- 在WPF中使用FontAwesome之类的字体图标
我之前在博客中介绍过几个矢量图库网站,在WPF程序中,一般接触到的矢量图标资源有XAML.SVG.字体这三种格式.XAML是标准格式就不说了,SVG并不是直接支持的,不过微软提供了Expression ...
- redux状态管理和react-redux的结合使用
一:调试 注意:Redux调试工具.谷歌中搜redux同理react 新建store的时候判断window.devToolsExtension使用compose(组合函数)结合thunk插件和wind ...
- Linux系统下,启动Tomcat有时报Address already in use
一.Linux系统下,启动Tomcat有时报Address already in use<null>... 1.那是因为你的tomcat已经启动了tomcat自带的关闭脚本,有时候关闭看上 ...
- Android视图SurfaceView的实现原理分析(示例,出错代码)
在Android系统中,有一种特殊的视图,称为SurfaceView,它拥有独立的绘图表面,即它不与其宿主窗口共享同一个绘图表面.由于拥有独立的绘图表面,因此SurfaceView的UI就可以在一个独 ...
- 关于json对象的删除
摘自:http://xosadan.iteye.com/blog/1100383 关于json对象的删除 一个json对象在后台产生了,但是有些数据可能无效或者不合法,所以需要在前台作些例外处理,比如 ...