UVA 10820 交表

#include<iostream>
#include<string>
#include<string>
#include<string.h>
#include<stdio.h>
#include<queue>
#include<math.h>
#include<vector>
#include<stdlib.h>
#define maxn 50000
#include<algorithm>
using namespace std;
int phi[maxn];
void phi_table(int n){
    for(int i=2;i<=n;i++) phi[i]=0;
    phi[1]=1;
    for(int i=2;i<=n;i++){
        if(!phi[i])
            for(int j=i;j<=n;j+=i){
                if(!phi[j]) phi[j]=j;
                phi[j]=phi[j]/i*(i-1);
            }
    }
}
int main(){
  int n;
  while(cin>>n){
        if(n==0) break;
  phi_table(n);
  int sum=0;
  for(int i=2;i<=n;i++){
    sum+=phi[i];
  }
  sum=sum*2+1;
  cout<<sum<<endl;
  }
   return 0;
}

  

时间: 2024-08-02 11:40:29

UVA 10820 交表的相关文章

UVa 10820 (打表、欧拉函数) Send a Table

题意: 题目背景略去,将这道题很容易转化为,给出n求,n以内的有序数对(x, y)互素的对数. 分析: 问题还可以继续转化. 根据对称性,我们可以假设x<y,当x=y时,满足条件的只有(1, 1). 设f(n)为 集合S{(x, y) | x<y且x.y互素} 的个数,则所求答案为2f(n)+1 f(n)表达式为: ,其中φ(n)为欧拉函数 这里有欧拉函数的一些介绍 1 #include <cstdio> 2 3 const int maxn = 50000; 4 5 int ph

17115 ooxx numbers 交表

17115 ooxx numbers 时间限制:1000MS  内存限制:65535K提交次数:0 通过次数:0 题型: 编程题   语言: G++;GCC Description a number A called oo number of a number B if the sum of all As factor is the number B. (A,B) is a pair of ooxx numbers if A is the oo number of B and B is the

UVa 1583打表

背景:1--TLE:超时,没有考虑到时间复杂度,开始对每一个数都从1开始到99999,这样就是O(t*key)这样20组大数就可以超时.2--WA:3--WA都是把数字误以为最多4位了,其实是五位!!!. 思路:找出i(从1到100000)产生的数n,i是n的生成元,由于最多5位数字相加,所以n-i<50.对于每个要找生成元的数t,如果t大于50,只需搜索(t-50,t). 学习:1.对于所有情况最多10万级别的可以打表. #include<stdio.h> int str[99999]

UVA 10820 Send a Table 数论 欧拉函数

题目链接: https://vjudge.net/problem/UVA-10820 题目描述: 给你一个N, N <= 50000, 让你寻找N之内互素数的个数 解题思路: 欧拉函数, 由于位置颠倒是两个解, 在小于N的范围内只有(1, 1)x, y相等, 其他的都是不等的, 所以我们只需要算phi(2) + phi(3) + ...... phi(n), 然后 * 2 + 1即可 代码: #include <iostream> #include <cstdio> #inc

UVA 10820 Send a Table

https://vjudge.net/problem/UVA-10820 题意: 有一张表 f[x][y],共x*y个数 现在要删去所有的 f[x*k][y*k] ,k>1 最后还剩多少个数 题意转化:有多少个二元组(x,y)满足 gcd(x,y)=1 若x<y,则 f[][y]=phi(y) 所以 ans= (2* Σ phi(y))+1   y∈[2,n] 加的1为(1,1) 线性筛出欧拉函数求和即可 #include<cstdio> #define N 50001 using

SpringMVC--提交表单

今天使用AbstractCommandController做一个提交表单的样例 (1)首先,建立一个User.java package com.zk.domain; import java.util.Date; public class User { private Integer id; private String name; private String age; private String birthday; public Integer getId() { return id; }

uva 10820

欧拉函数..... #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; const int maxn=50000+10; int pp[maxn]; int sum[maxn]; int n; void ola() { memset(pp,0,sizeof(pp)); memset(sum,0,sizeof(sum

例题10-7 交表 UVa10820

1.题目描述:点击打开链接 2.解题思路:本题实质上是要求满足1≤x,y≤n,且x,y互素的个数.除了(1,1)外,其余的x,y各不相同.设x<y有f(n)个,那么最终答案是2*f(n)+1.关于f(n)的计算就是不超过n的所有数的欧拉函数的和.而求解1~n中所有数的欧拉函数的时间复杂度是O(N*loglogN). 3.代码: #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<algorithm> #inc

UVA - 10820欧拉函数的应用

这是一道很基础的欧拉函数的题目 题意要求  (x,y) 互质 &&x<=n&&y<=n 求互质对数 可以运用容斥,求出 phi(n)=n(1-1/n1)(1-1/n2)......(1-1/nk); 因为(2,4) (4,2) 算两对,所以 答案为 2*f(n)+1; #include<stdio.h> #include<string.h> #include<stdlib.h> #include<iostream>