POJ 2773 Happy 20,062 points + allowances (introductory

Source: Internet
Author: User

Topic Link: Click to open the link

Test instructions

Enter N, k for n coprime number of K (this number may >n)

Ideas:

Solve (mid) indicates how many and n coprime are in [1,mid], and then the smallest mid makes the coprime number ==k

Solve (x) implementation:

Number of coprime with n = all number-N non-coprime = all number-(with N having a factor-with n having 2 factors + and n having 3 factors)

The number of factors that form pressure n, which is then obtained according to the formula above.



#include <stdio.h> #include <iostream> #include <algorithm> #include <sstream> #include < stdlib.h> #include <string.h> #include <limits.h> #include <vector> #include <string># Include <time.h> #include <math.h> #include <queue> #include <stack> #include <set># Include <map>const int inf = 1e8;const double eps = 1e-8;const double pi = ACOs ( -1.0); template <class t> Inli      ne BOOL Rd (T &ret) {char c; int sgn;      if (C=getchar (), c==eof) return 0; while (c!= '-' && (c< ' 0 ' | |      C> ' 9 ')) C=getchar ();      sgn= (c== '-')? -1:1;      ret= (c== '-')? 0: (c ' 0 ');      while (C=getchar (), c>= ' 0 ' &&c<= ' 9 ') ret=ret*10+ (c ' 0 ');      RET*=SGN;  return 1;      } template <class t> inline void pt (T x) {if (x <0) {Putchar ('-'); x =-X;}      if (x>9) pt (X/10);  Putchar (x%10+ ' 0 '); }using namespace Std;typedef Long long ll;typedef pair<int,int> PII; const int N = 1e5;ll prime[n],primenum;//has primenum Prime math.hvoid Prime (ll max_prime) {primenum=0;prime[primenum++]=2;for (ll i=3;i<=Max_ prime;i+=2) for (ll j=0;j<primenum;j++) if (i%prime[j]==0) Break;else if (prime[j]>sqrt (double) i) | | j== primenum-1) {prime[primenum++]=i;break;}}  ll L, K;vector<ll>fac;void Factor (ll x) {fac.clear (); for (int i = 0; i < primenum && prime[i]*prime[i]<= X i++) {if (X%prime[i]) continue;fac.push_back (Prime[i]), while (x%prime[i]==0) x/=prime[i];} if (x!=1) fac.push_back (x);//cout<<x<< "";p UTS ("factor:"); for (int i = 0; I < fac.size ();  i++) {//pt (Fac[i]), puts ("* *"),//}}ll Solve (ll x) {//calculated with X having 2 or more factor numbers if (x<=0) return 0;if (x = = 1) return 1;ll sum = 0, siz = (int) fac.size (); for (int i = 1; i < (1<<siz); i++) {ll LCM = 1, one = 0;for (int j = 0; J < Siz; J + +) if (I & (1&LT;&LT;J)) {LCM *= fac[j];one++;} if (one&1) sum + = x/lcm;else sum-= X/LCM;} return x-sum;} int main () {PRIME (1e5+10), while (cin>>l>>k) {factor (L); ll L = 1, R = 1e18, ans = 1;while (L <= R) {ll mid = (l+r) >>1;ll OK = Solve (mid); if (ok<k) L = mid+1;else {ans = mid; R = Mid-1;}} PT (ANS);    Puts ("");} return 0;}


Solve (x) implementation:

POJ 2773Happy 20,062 + allowance (introductory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.