|
|
вернуться в форумThis is the right solution Послано netman 24 мар 2013 15:18 This is the right solution Sorry for my english var ans: array[1..1000] of longint; n,m,y,q,i: longint; function BinPow(x,y: longint): longint; begin if y=1 then BinPow:=x else if y mod 2=0 then BinPow:=sqr(BinPow(x,y div 2)) mod M else BinPow:=(sqr(BinPow(x,y div 2))*x) mod M; end; begin readln(n,m,y); q:=0; for i:=0 to m-1 do begin if BinPow(i,n)=y then begin inc(q); ans[q]:=i; end; end; for i:=1 to q do write(ans[i],' '); if q=0 then writeln(-1); end. Re: This is the right solution Послано ELDVN 2 ноя 2015 00:11 My solve in C++: #include <iostream> #include <string> #include <vector> #include <set> #include <queue> #include <map> #include <stack> #include <algorithm> #include <bitset> #include <cstring> #include <cmath> #include <cstdlib> #include <cstdio> #include <iomanip> #define F first #define S second #define ll long long #define len length() #define sqr(x) x*x #define pb push_back #define mp make_pair #define sz(x) ((int) (x).size()) #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define bp(x) __builtin_popcount(x) #define INF numeric_limits<long long int>::max() #define frp freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++) const int maxn = (int)1e6; const int mod = (int)1e9 + 7; using namespace std; __int64 n,m,y;
int binpow(int a, int n){ if (n == 0) return 1; if (n % 2 == 1) return (binpow (a, n-1)*a)%m; else{ int b = (binpow(a, n/2)); return (b*b)%m; } }
bool ok; main(){ scanf("%I64d%I64d%I64d",&n,&m,&y); for(int i=0; i < m; i++){ if(binpow(i,n)%m==y){ cout<<i<<" "; ok=1; } } if(!ok) return cout<<"-1",0;
return 0; } Re: This is the right solution What it is? else if y mod 2=0 then BinPow:=sqr(BinPow(x,y div 2)) mod M else BinPow:=(sqr(BinPow(x,y div 2))*x) mod M; |
|
|