# Codeforces Round #489 (Div. 2)

Source: Internet
Author: User
Tags gcd

codeforces Round #489 (Div. 2)A. Nastya and an Array
#include <bits/stdc++.h>#define REP (i,a,b) for (int i=a;i<=b;++i)#define FREP (I,A,B) for (int i=a;i>=b;--i)#define MEM (w) memset (w,0,sizeof (w) )#define PB Push_backtypedef Long LongllConst intN = -;Const intINF =0x3f3f3f3f;inline intRead () {CharC=getchar ();intx=0, f=1; while(c<' 0 '|| C>' 9 '){if(c=='-') f=-1; C=getchar ();} while(c>=' 0 '&&c<=' 9 ') {x=x*Ten+c-' 0 '; C=getchar ();}returnX*f;}using namespaceStdintn,ans;map<int,int> M;intMain () {n = read (); Rep (I,1, N) {intX=read ();if(x&&! M[x]) {m[x]=1;        ++ans; }} printf ("%d\n", ans);return 0;}
B. Nastya Studies Informatics\ (GCD (A, B) = x, LCM (A, b) = y\), i.e.\ (gcd (\frac {a}{x},\frac {b}{x}) = 1, \frac {a*b}{x} = \frac{a}{x}*b = y\), then we can enumerate directly\ (\frac{a}{x}\)To check if a, B is an answer within [l,r], just enumerate\ (\sqrt{y}\)The number can be within. (the card too long led to c no time to check ...) It's just cold.
#include <bits/stdc++.h>#define REP (i,a,b) for (int i=a;i<=b;++i)#define FREP (I,A,B) for (int i=a;i>=b;--i)#define MEM (w) memset (w,0,sizeof (w) )#define PB Push_backtypedef Long LongllConst intN = -;Const intINF =0x3f3f3f3f;inlinell read () {CharC=getchar (); ll x=0, f=1; while(c<' 0 '|| C>' 9 '){if(c=='-') f=-1; C=getchar ();} while(c>=' 0 '&&c<=' 9 ') {x=x*Ten+c-' 0 '; C=getchar ();}returnX*f;}using namespaceStd;ll x,y,l,r,ans,ans2;set< pair<ll,ll> > S;ll LCM (ll a,ll b) {returnA*B/__GCD (A, b);}intMain () {l=read (); R=read (); X=read (); Y=read ();if(x==y) {if(L&LT;=X&AMP;&AMP;X&LT;=R)returnPuts"1"),0;Else returnPuts"0"),0; }if(y%x| | Y&LT;X)returnPuts"0"),0;if(y==1){if(x==1&AMP;&AMP;L&LT;=X&AMP;&AMP;X&LT;=R)returnPuts"1"),0;Else returnPuts"0"),0; } for(LL i=1; i*i<=y;++i) {if(y% (x*i) = =0&AMP;&AMP;__GCD (i*x,y/i) ==X&AMP;&AMP;LCM (i*x,y/i) ==y) {if(l<=i*x&&y/i<=r&&l<=y/i&&i*x<=r) S.insert (Make_pair (i*x,y/i)), S.insert (make        _pair (y/i,i*x)); }} printf ("%d\n",(int) s.size ());return 0;}
C. Nastya and a wardrobe slightly expanded to write, you can find the law, and then the formula is very obvious, see the code specifically. Pay attention to the Special award.
#include <bits/stdc++.h>#define REP (i,a,b) for (int i=a;i<=b;++i)#define FREP (I,A,B) for (int i=a;i>=b;--i)#define MEM (w) memset (w,0,sizeof (w) )#define PB Push_backtypedef Long LongllConst intN = -;Const intINF =0x3f3f3f3f;inline intRead () {CharC=getchar ();intx=0, f=1; while(c<' 0 '|| C>' 9 '){if(c=='-') f=-1; C=getchar ();} while(c>=' 0 '&&c<=' 9 ') {x=x*Ten+c-' 0 '; C=getchar ();}returnX*f;}using namespaceStdConst intMoD =1e9+7; ll Q_pow (ll A,ll b) {ll ans=1; while(b) {if(b&1) ans= (ans*a)%mod;        A= (a*a)%mod; b>>=1; }returnAns;} ll N,k;intMain () {scanf ("%i64d%i64d", &n,&k);if(n==0)returnPuts"0"),0;    N%=mod; printf"%i64d\n", ((Q_pow (2K+1) *n)%mod-(Q_pow (2K-1)%mod+mod)%mod);return 0;}
D. Nastya and a Game\ (p = s*k≤2*10^{18}\), so if each multiply by a number greater than 1, p requires at most\ (\log{(2*10^{18})}\)multiplied by the number. Then just press test instructions to enumerate the left endpoint, each time jumping to the next non-1 position, for a continuous period of 1, calculate the maximum, the minimum value can be judged whether to include the location of the condition.
#include <bits/stdc++.h>typedef Long LongllConst intN =2e5+ -;using namespaceStdintN,k;ll A[n],sum[n];intNxt[n];voidInit () { for(intI=1; i<=n;++i) Sum[i]=sum[i-1]+a[i]; Nxt[n] = n+1; for(intI=n-1; i>=1;-I.) {if(A[i+1] ==1) Nxt[i] = Nxt[i+1];ElseNxt[i] = i+1; }}intCk1 (ll A, ll b) {returnA *1.0> long_max*1.0/b;}intCK (ll x1, ll x2, ll p) {if(p%k==0) {p/=k;if(X1&LT;=P&AMP;&AMP;P&LT;=X2)return 1; }return 0;}intMain () {scanf ("%d%d", &n,&k); for(intI=1; i<=n;++i) scanf ("%i64d", &a[i]); Init ();intAns =0; for(intL=1; L<=n;++l) {ll x=1; for(intR=l; r<=n; R=nxt[r]) {if(Ck1 (x, A[r])) Break; X*=A[R];if(CK (sum[r]-sum[l-1], Sum[nxt[r]-1]-sum[l-1], x)) ++ans; }} printf ("%d\n", ans);}

Later with Markdown, but the code highlighting problem has not been solved, so ...

Codeforces Round #489 (Div. 2)

Related Keywords:

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.