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的更多相关文章
随机推荐
- js作用域对象与运用技巧
1. JS作用域 1.1 全局作用域和局部作用域 函数外面声明的就是 全局作用域 函数内是局部作用域 全局变量可以直接在函数内修改和使用 变量,使用var是声明,没有var是使用变量. 如果在函数内使 ...
- Problem Z: 百鸡问题
#include <stdio.h> int main() { int i, j, k; ; i <= ; i++ ) ; j <= ; j++ ) ; k <= ; k ...
- Codeforces Round #127 (Div. 1) E. Thoroughly Bureaucratic Organization 二分 数学
E. Thoroughly Bureaucratic Organization 题目连接: http://www.codeforces.com/contest/201/problem/E Descri ...
- PHP 正则表达式匹配 img ,PHP 正则提取或替换图片 img 标记中的任意属性。
PHP正则提取或替换img标记属性 PHP 正则表达式匹配 img ,PHP 正则提取或替换图片 img 标记中的任意属性. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...
- Ubuntu 16.04/CentOS 6.9安装Node.js 6.9.5
Ubuntu: CentOS: wget https://nodejs.org/dist/v6.9.5/node-v6.9.5-linux-x64.tar.xz tar -xvf node-v6.9. ...
- [典型漏洞分享]YS VTM模块存在格式化字符串漏洞,可导致VTM进程异常退出【高危】
YS VTM模块存在格式化字符串漏洞,可导致VTM进程异常退出[高危] 问题描述: YS VTM模块开放对外监听端口(8554和8664),此次使用sulley fuzzing框架对监听在8664端口 ...
- Inno Setup入门(二十一)——Inno Setup类参考(7)
复选框 复选框(CheckBox)用于多个并不互斥的几个选项中作出一个或者多选择,例如字体可以有粗体.斜体和下划线,这三种状态可以任意组合,像这样的选项可以采用复选框实现.Pascal脚本中对应的类是 ...
- vagrant public_network 自定义静态 ip配置方法
Vagrant 创建虚拟化开发环境 Vagrant是一个基于Ruby的工具,用于创建和部署虚拟化开发环境.它 使用Oracle的开源VirtualBox虚拟化系统,使用 Chef创建自动化虚拟环境. ...
- Quartz_TimeJob例子(C#)
执行入口: using System; using System.Collections.Generic; using log4net; using Quartz; using ypt_base.Co ...
- 将图片转换为Base64字符串公共类抽取
public class ImageToBase64 { //图片转化成base64字符串 public static String GetImageStr(String path,int width ...