题目的愿意非常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. Largest Smallest Cyclic Shift

    Largest Smallest Cyclic Shift 题目来源: Atcoder Code Festival 2017 Qual B Problem F 题目大意: 有\(X\)个字符'a',\ ...

  2. CDOJ 1277 智商杯考试 每周一题 div2 二分+数学

    智商杯考试 题目连接: http://acm.uestc.edu.cn/#/problem/show/1277 Description 你是一个挂科选手. 你现在正在考试,你很方. 你参加的考试叫做智 ...

  3. llvm之旅第一站 - 编译及简单使用 LLVM 图解

    http://www.nagain.com/activity/article/4/ http://blog.csdn.net/snsn1984/article/details/8593380

  4. TSQL语言基础笔记之单表查询

    db_id()函数 返回对象的id,如果返回的对象为null,则判断不存在 if db_id('testdb') is null --判断数据库是否存在 create database testdb ...

  5. 让你明白response.sendRedirect()与request.getRequestDispatcher().forward()区别

    JSP中response.sendRedirect()与request.getRequestDispatcher().forward(request,response)这两个对象都可以使页面跳转,但是 ...

  6. 【转载】【Todo】电商架构相关技术分析

    看了一篇文章: http://kb.cnblogs.com/page/193670/    淘宝应对"双11"的技术架构分析 没怎么看懂,有时间再看.

  7. MySql 建库建表脚本

    1.建库 CREATE DATABASE test DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; 2.建表脚本 CREATE TABLE `c ...

  8. Appium九宫格滑动解锁

    1.适配各种机型,首先获取整个解锁元素的坐标 2.代码实现 WebElement lockPattern = driver.findElement(By.id("com.android.se ...

  9. Cannot call sendError() after the response has been committed(filter问题)

    就是因为执行了filter的dofilter方法中 chain.doFilter(request,response)了 执行了两遍 if(){}else{chain.doFilter(request, ...

  10. web页面内容优化管理与性能技巧

    来源:GBin1.com 回 想一下,以前我们不得不花费大量时间去优化页面内容(图片.CSS等等),如今用户有更快速的互联网链接,我们似乎能够使用更大的图像或更大的闪 存文件,里面包含的有视频或者图片 ...