LightOJ 1370 Bi-shoe and Phi-shoe 数论
题目大意:f(x)=n 代表1-x中与x互质的数字的个数。给出n个数字a[i],要求f(x)=a[i],求x的和。
思路:每个素数x 有x-1个不大于x的互质数。则f(x)=a[i],若a[i]+1为素数则x=a[i]+1,否则a[i]++直到得到素数位置。
#include<cstdio>
#include<stdio.h>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#define INF 0x3f3f3f
#define MAX 1000005
#define MOD 1000000007 using namespace std; long long p[MAX],v[MAX]; void GetPrime()//打素数表
{
int i,j,cnt=;
memset(v,,sizeof(v));
memset(p,,sizeof(p));
p[]=;
for(i=; i<=; i++)
{
if(!v[i])
{
p[i]=;
for(j=i; j<=; j+=i)
{
v[j]=;
}
}
}
} int main()
{
GetPrime();
int T,i,j,cnt=,k,n;
long long sum;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
sum=;
for(i=;i<=n;i++)
{
scanf("%d",&k);
j=k+;
while(!p[j])
j++;
sum+=j;
}
printf("Case %d: %lld Xukha\n",cnt++,sum);
}
return ;
}
LightOJ 1370 Bi-shoe and Phi-shoe 数论的更多相关文章
- LightOJ 1370 Bi-shoe and Phi-shoe
/* LightOJ 1370 Bi-shoe and Phi-shoe http://lightoj.com/login_main.php?url=volume_showproblem.php?pr ...
- lightoj 1370 欧拉函数
A - Bi-shoe and Phi-shoe Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & % ...
- LightOJ 1370 - Bi-shoe and Phi-shoe (欧拉函数思想)
http://lightoj.com/volume_showproblem.php?problem=1370 Bi-shoe and Phi-shoe Time Limit:2000MS Me ...
- 数论-欧拉函数-LightOJ - 1370
我是知道φ(n)=n-1,n为质数 的,然后给的样例在纸上一算,嗯,好像是找往上最近的质数就行了,而且有些合数的欧拉函数值还会比比它小一点的质数的欧拉函数值要小,所以坚定了往上找最近的质数的决心—— ...
- Bi-shoe and Phi-shoe LightOJ - 1370(数论+素数筛)
题目链接:https://vjudge.net/problem/LightOJ-1370 题意:给你N个欧拉函数值,找出每一个大于等于该欧拉函数值的数,并且要求相加和最小. 题解:因为素数i的欧拉函数 ...
- Lightoj 1370 素数打表 +二分
1370 - Bi-shoe and Phi-shoe PDF (English) Statistics Time Limit: 2 second(s) Memory Limit: 32 MB ...
- LightOJ 1370 Bi-shoe and Phi-shoe【欧拉函数 && 质数】
题目链接: http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1370 题意: 给定值,求满足欧拉值大于等于这个 ...
- LightOJ 1370 Bi-shoe and Phi-shoe 欧拉函数+线段树
分析:对于每个数,找到欧拉函数值大于它的,且标号最小的,预处理欧拉函数,然后按值建线段树就可以了 #include <iostream> #include <stdio.h> ...
- LightOJ - 1370
Bi-shoe and Phi-shoe Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %lld & %llu S ...
随机推荐
- Java 泛型 泛型数组
Java 泛型 泛型数组 @author ixenos 先给结论 不能(直接)创建泛型数组 泛型数组实际的运行时对象数组只能是原始类型( T[]为Object[],Pair<T>[]为Pa ...
- CevaEclipse - 编译器attribute扩展
1.函数与变量的 Section Attribute void foobar (void) __attribute__ ((section (".CSECT mmm"))); vo ...
- 利用POI获取Excel中图片和图片位置
利用POI获取Excel中图片和图片位置(支持excel2003or2007多sheet) 转自:http://blog.csdn.net/delongcpp/article/details/8833 ...
- linux安装配置solr
一.JDK的安装和配置 下载.解压jdk-7u79-linux-x64.gz 1.tar -zxvf jdk-7u79-linux-x64.gz -c /usr/java/ 解压到/usr/java/ ...
- append()常见错误
实例1 empty = [] print empty.append("Hi") 输出None print empty 输出["Hi"] 错误: 直接打印变量带a ...
- 获取android源码中遇到的问题
最近项目相当紧张,回家之后还需要继续研究android源码. 从网上找了一些资料,下载过程中还是遇到了很多问题.这里罗列一下: 1. 下载Repo过程中提示证书问题: curl https://dl- ...
- asp.net URL DES加密 什在URL中的使用
DES 加密 有时会有 + = 这些特殊字符串 Server.UrlDecode(Request["UserName"]) //能解决 = 号,但是 +号会变成空格 HttpUt ...
- DirectShow音频采集声音不连续问题分析与解决办法经验总结
最近广州大雨不断,并且多数无前兆,突然就来场大雨,给同学们降降温,说来本也是好事,但有时候下的真不是时候,最近这段时间都是即将下班了,大雨就来了,昨晚快下班前又出现了大雨,北方人总爱忘带雨伞,这不就被 ...
- c#控制其他程序窗口位置
//调用Win32 API [System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint ...
- POJ1113 Wall 凸包
题目大意:建立围墙将城堡围起来,要求围墙至少距离城堡L,拐角处用圆弧取代,求围墙的长度. 题目思路:围墙长度=凸包周长+(2*PI*L),另外不知道为什么C++poj会RE,G++就没问题. #inc ...