Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #3227
- #include<fstream>
- #define nebunie 1000006
- using namespace std;
- ifstream cin("tramvaie.in");
- ofstream cout("tramvaie.out");
- int phi[nebunie+1];
- void problemaproasta()
- {
- int i,p;
- for(i=1;i<=nebunie;i++)phi[i]=i;
- for(p=2;p<=nebunie;p++)
- {
- if(phi[p]==p)
- {
- phi[p]=p-1;
- for(i=2*p;i<=nebunie;i+=p)
- {
- phi[i]=(phi[i]/p)*(p-1);
- }
- }
- }
- }
- int n,x,i;
- int main()
- {
- cin>>n;
- problemaproasta();
- for(i=1;i<=n;i++)
- {
- cin>>x;
- cout<<phi[x]<<" ";
- }
- return 0;
- }
- #2433
- #include<fstream>
- #include<cmath>
- #include<cstring>
- using namespace std;
- ifstream cin("cufar.in");
- ofstream cout("cufar.out");
- int magic(int x,int k)
- {
- int p=0,i;
- while(x%2==0){p=1;x/=2;}
- if(p==k)return 2;
- else
- {
- for(i=3;i*i<=x&&p<k;i+=2)
- {
- if(x%i==0){p++;while(x%i==0)x/=i;}
- }
- if(x!=1&&p<k)return x;
- return i-2;
- }
- }
- int p,n,x,k;
- long long s,i;
- int main()
- {
- cin>>p>>n;
- if(p==1)
- {
- cin>>x>>k;
- cout<<magic(x,k);
- }
- else
- {
- for(i=1;i<=n;i++)
- {
- cin>>x>>k;
- s+=magic(x,k);
- }
- cout<<s;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement