mbah_bejo

prima cepet

Nov 27th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <math.h>
  4. #include <string.h>
  5.  
  6. //  bool prime[1001];
  7. int ngeprimain( long long n)
  8. {
  9.     long long i;
  10.     for ( i=2; i*i<=n; i++)
  11.     {
  12.         if (n%i==0) return 0;  
  13.     } return 1;
  14. }
  15.  
  16. int main()
  17. {
  18. long long pok,maha,hari,i;
  19. //bool prime[1001];
  20. long long mod=1000000007;
  21.    
  22.     scanf("%lld",&pok);
  23.     while(pok)
  24.     {
  25.         scanf("%lld%lld",&maha,&hari);
  26.         long long tot=maha;
  27.         for(i=2;i<=hari;i++)
  28.         {
  29.         if(ngeprimain(i) )
  30.         {
  31.             tot*=maha;
  32.             tot%=mod;
  33.         } else
  34.         {
  35.             tot*=(maha-1);
  36.             tot%=mod;
  37.         }
  38.            
  39.         }
  40.         printf("%lld\n",tot);
  41.         pok--;
  42.     } return 0;
  43. }
Add Comment
Please, Sign In to add comment