题目的愿意非常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的更多相关文章

随机推荐

  1. 都9102年了,还不会Docker?10分钟带你从入门操作到实战上手

    Docker简述 Docker是一种OS虚拟化技术,是一个开源的应用容器引擎.它可以让开发者将应用打包到一个可移植的容器中,并且该容器可以运行在几乎所有linux系统中(Windows10目前也原生支 ...

  2. 零起点学算法08——简单的输入和计算(a+b)

    #include <stdio.h> int main() { int a; int b; scanf("%d %d",&a,&b); printf(& ...

  3. HDU 4417 Super Mario(划分树)

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. ADO特有的流化和还原

    ADO特有的流化和还原 {*******************************************************}{ }{ ADO 数据流化 }{ }{ 版权所有 (C) 20 ...

  5. andriod 获得时间

    import java.text.SimpleDateFormat;import java.util.Date; public static String getCurrentTime() { Sim ...

  6. [Linux] 守护进程和守护线程

    对于JAVA而言,一般一个应用程序只有一个进程——JVM.除非在代码里面另外派生或者开启了新进程. 而线程,当然是由进程开启的.当开启该线程的进程离开时,线程也就不复存在了. 所以,对于JAVA而言, ...

  7. unitest跳过测试用例

    http://www.51testing.com/html/35/n-3718035.html @unittest.skip(u"强制跳过示例") @unittest.skip(u ...

  8. 十二.spring-boot使用spring-boot-freemarker

    ①.在springMVC中:它代表着view层组件 ②.为什么使用freemarker:简单容易学.逻辑分明 ③.freemarker优点:它不依赖servlet.网络或者web环境 一.创建一个ma ...

  9. Linux驱动虚拟地址和物理地址的映射

    一般情况下,Linux系统中,进程的4GB内存空间被划分成为两个部分------用户空间和内核空间,大小分别为0~3G,3~4G. 用户进程通常情况下,只能访问用户空间的虚拟地址,不能访问到内核空间. ...

  10. Perforce查看workspace sync到的changlist

    一 查看workspace sync到的changelist perforce的workspace其实是一些特定版本的文件的 结合,相比只将workspace对应到某个特定的changelist,此方 ...